4
If you could help me with a question, I would really appreciate it! So, I’m very junior in javascript and I’m doing an exercise, where I wanted to put the results of my cycle out to appear in HTML, but I’m not getting there.
Basically, I get two values as input and one of them is the cost of the first day of holidays to which I want to add 20% later every day.
const cost = document.querySelector(".input1");
const days = document.querySelector(".input2")
const btnConvert = document.querySelector(".btn-converter");
function calculoDespesaViagem(cost, days) {
days = [];
const percentage = 1.2;
let maxDays= days.length -1
for (let i = 1; i < maxDays; i++) {
cost = cost * percentage;
document.getElementByClassName("li").innerHTML = (` valor do dia ${i + 1}: ${cost}`);
}
return cost;
}
btnConvert.addEventListener('click', function () {
calculoDespesaViagem(cost.value, days.value);
});
<section class="container">
<h1>Exercícios</h1>
<label class="label"
>Valor do primeiro dia de viagem
<input type="number" value="50" class="input1" />
</label>
<label class="label"
> Total de dias de viagem
<input type="number" value="4" class="input2" />
</label>
<button class="btn btn-converter" id="btn-converter">Calcular Custos</button>
<ul class="list">
<li class="li"></li>
</ul>
<!--<h2 class="total" id="h2"></h2>-->
</section>
basically I intended to appear in html more or less like this:
day 1 value: 60
day 2 value: 72
day 3 value: 86.39
day 4 value: 103.68
...
Got it. Thanks a lot for your help ! :)
– Ana Sofia
Please... we’re here for this ;)
– Marcos Alexandre