+ 2

Leap Years

Why is it not working? For example if I put in the number 4 and I press convert it will come out as Not A Leap Year? Any solution to fix this problem? https://code.sololearn.com/WYG87Ior0jm4/?ref=app

6th Mar 2022, 7:16 PM
Your Mom
Your Mom - avatar
21 Answers
+ 5
Condition is if year%4==0 and year%100 != 0 year is a leap year else if year%400==0 year is a leap year else year is not a leap year
6th Mar 2022, 7:38 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
+ 4
1900 is divisible by 4 and 100 but it is not a leap year.
6th Mar 2022, 7:53 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
+ 2
Your if is wrong, it should be more like this: if (x % 4 == 0 || x % 400 == 0)
6th Mar 2022, 7:38 PM
Paul
Paul - avatar
+ 2
OHH NEVERMIND I GET IT NOW
6th Mar 2022, 7:56 PM
Your Mom
Your Mom - avatar
+ 1
Why can it nake it so (yr % 100 == 0) { document.getElementById…”Not Leap Year” } unless yoi csn do do that
6th Mar 2022, 8:15 PM
Your Mom
Your Mom - avatar
6th Mar 2022, 8:22 PM
Your Mom
Your Mom - avatar
+ 1
You see?
6th Mar 2022, 8:22 PM
Your Mom
Your Mom - avatar
+ 1
Years multiple of 100 are century years 1000,1100,1200, .., 1900,2000,.. are divisible by 4 and 100 but all not leap years 1900 is divisible by 100 but not leap year. 2000 is divisible by 100 but leap year. Using || (or) operator result true if any one condition is true, no need both. Leap Year must be divisible by 4 but not divisible by 100 Or Leap Year must divisible by 400
6th Mar 2022, 8:44 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
+ 1
Hmm? But my document says Not A Leap Year?
6th Mar 2022, 8:47 PM
Your Mom
Your Mom - avatar
+ 1
No. It says leap year for 1900 simple it should be divisible of 4 and not divisible by 100 . otherwise divisible by 4 and 400... Else cases not a leap year..
6th Mar 2022, 8:52 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
+ 1
Ik 1900 isnt a leap year but every 100 yrs i want my code to say “Not a Leap Year” abd thats what i did but it didnt work
6th Mar 2022, 8:54 PM
Your Mom
Your Mom - avatar
+ 1
Make changes as I mentioned in my first post. It works. Otherwise don't work.
6th Mar 2022, 9:01 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
+ 1
Ok
6th Mar 2022, 9:01 PM
Your Mom
Your Mom - avatar
+ 1
I think im starting to get it jow tho
6th Mar 2022, 9:07 PM
Your Mom
Your Mom - avatar
+ 1
So thanks
6th Mar 2022, 9:07 PM
Your Mom
Your Mom - avatar
0
Okay, so yr % 100 != 0, what is the poibt of the 0?
6th Mar 2022, 7:45 PM
Your Mom
Your Mom - avatar
0
Still not get it? See this, https://www.almanac.com/content/when-next-leap-year You're welcome..
6th Mar 2022, 9:17 PM
Jayakrishna 🇮🇳
Jayakrishna 🇮🇳 - avatar
0
Your Mom you can condense your code to: function Leap_Year() { document.getElementById("demo").innerHTML = !((yr % 4) || (!(yr % 100) && yr % 400)) ? "Leap Year": "Not a Leap Year"; } Or use Date, and check if February have 29 https://code.sololearn.com/WslBGD5wir7k/?ref=app
7th Mar 2022, 1:30 PM
Bob_Li
Bob_Li - avatar
- 1
const leap_year = year%4&&year100!=0?year%400?yes:yes:no
8th Mar 2022, 7:36 AM
Shai Shab
Shai Shab - avatar
- 1
Can anyone create new code for me Because my has so many errors
8th Mar 2022, 6:40 PM
sai sai