0
I’m in an online Jquery course where the teacher proposed a code like this:
var inicia = function(){
var valorTotalItens = $('.valor-total-item');
var valorBase = 0;
for (var i = 0; i < valorTotalItens.length; i++) {
var valorItemTotal = $(valorTotalItens[i]);
var valorItem = parseFloat(valorItemTotal.text());
valorBase = valorBase + valorItem;
}
$('#quantidade-itens').text(valorTotalItens.length);
$('#valor-itens').text(valorBase);
}
$(inicia);
however, I wrote the last line before it passed, and wrote otherwise
inicia();
I wanted to know the difference, and why, of my code worked, even after the teacher said it was wrong, and that it should not run.
Thank you man :D
– Murilo Melo