4
I’m wondering where I went wrong in this code where the user types a year and appears on the screen whether that year is leap or not.
function calcularBissexto() {
var bi = parseFloat(document.getElementById('bissexto').value);
var msg = document.getElementById('msg');
for (bi % 4; bi % 100; bi % 400) {
if (bi % 4 == 0 || bi % 100 == 0 || bi % 400 == 0) {
msg.innerHTML += 'E bissexto'
} else {
msg.innerHTML += 'Nao e bissexto';
}
}
}
<input type="number" id="bissexto">
<button onclick="calcularBissexto()">Click</button>
<div id="msg"></div>
your code not worked. You used January on Date and not consider Culture. And Why are you using const? I tested your code and got errors.
– user12100
First, the months go from 0 to 11, second and a constant value , know whether it is or not, therefore const
– Marcelo Batista
I asked because I used your code and tested with the year 2016 and it went bad (2016 is bisext), but when I switched to (year, 2, 29) it worked (with some changes, because the way it is, in practice it went wrong, and is displaying your code instead of the message) . It would be nice if you put up a snippet to show in practice how to use .
– user12100