+ 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

2nd Mar 2019, 3:26 PM
Ghost rider
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)
2nd Mar 2019, 3:36 PM
ŠØŠ°Ń‰Šø Š Š°Š½Š¶Š°Š½
ŠØŠ°Ń‰Šø Š Š°Š½Š¶Š°Š½ - avatar
+ 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.
2nd Mar 2019, 3:41 PM
Nathan Lewis
Nathan Lewis - avatar