+ 2
What's wrong in my code?
https://code.sololearn.com/WRRL11qsD1NS/?ref=app When I am getting the "hour" by today.getHours () if loop is working I. E. Deducting 12 if hour is greater than 12. But when I m giving input to hour. It's not deducting 12
2 Answers
+ 1
It's bcz prompt will return you a string and not an integer which obviously you need to use in the if part.
Just convert that hour to number by using Number(hour)
+ 1
You are writing the hour to your time variable before checking whether it is > 12. time is taking the initial hour variable. Change time right before you write it to the document.