0

Out pm if it's greater than 12 else am

Help me fix this code to output pm if it's greater than 12 else output am var hour = 10 var zone = (hour<12) ? "am":"pm" console.log(zone)

29th Sep 2023, 8:14 PM
Brian Pascal
Brian Pascal - avatar
9 odpowiedzi
+ 1
Assuming you have var hour from the lesson already: if(hour <=12) { console.log("am") } else{ console.log("pm") }
2nd Oct 2023, 6:31 PM
Juan
Juan - avatar
0
//You should use “let” instead of “var”
29th Sep 2023, 10:43 PM
Annihilate
Annihilate - avatar
0
//And here is the code let hour = 10; let zone = “”; if (hour < 12){ zone = “pm” } else { zone = “am” } console.log(zone)
29th Sep 2023, 10:47 PM
Annihilate
Annihilate - avatar
0
I've tried this still not working
30th Sep 2023, 7:03 AM
Brian Pascal
Brian Pascal - avatar
0
//ok, here's the correct code let hour = 10; let zone = ""; if (hour < 12){ zone = "pm" } else { zone = "am" } console.log(zone)
30th Sep 2023, 8:23 PM
Annihilate
Annihilate - avatar
0
I was just doing the JavaScript lessons on here and I also came across this problem. Trey has answered it correctly for a sample case. Assume the var hour will be given, so that line would be unnecessary in the lesson. Also, the operand should be <=12 since 12 is still am.
30th Sep 2023, 9:05 PM
Juan
Juan - avatar
0
Hi Juan, would you mind writing the code 🙏
2nd Oct 2023, 5:46 PM
Brian Pascal
Brian Pascal - avatar