How could I make leap years counter here? (code is in the descritpion) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How could I make leap years counter here? (code is in the descritpion)

https://code.sololearn.com/WLn5TDCBYn6f/#js As you can see, my code is a spaghetti one, I've tried to make a calculator between one and today's date. How would you make a leap years counter? Thanks :)

2nd Jan 2018, 9:01 PM
Ice
Ice - avatar
3 Answers
2nd Jan 2018, 9:29 PM
Elie Douaihy
Elie Douaihy - avatar
+ 1
@Elie thank you bud, you've saved me from the headaches! I adjusted the code for the JavaScript, and now its: var counter=0; while (yourYear<=currentYear){ var x = (yourYear % 4) == 0; var y = (yourYear % 100) != 0; var z = ((yourYear % 100 == 0) && (yourYear % 400 == 0)); if (x && (y || z)){ counter++; } yourYear++; }
2nd Jan 2018, 10:16 PM
Ice
Ice - avatar
+ 1
welcome 😊 nice code 👍
2nd Jan 2018, 10:19 PM
Elie Douaihy
Elie Douaihy - avatar