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)
9 RĂ©ponses
+ 1
Assuming you have var hour from the lesson already:
if(hour <=12) {
console.log("am")
}
else{
console.log("pm")
}
0
//You should use âletâ instead of âvarâ
0
//And here is the code
let hour = 10;
let zone = ââ;
if (hour < 12){
zone = âpmâ
} else {
zone = âamâ
}
console.log(zone)
0
I've tried this still not working
0
//ok, here's the correct code
let hour = 10;
let zone = "";
if (hour < 12){
zone = "pm"
} else {
zone = "am"
}
console.log(zone)
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.
0
Hi Juan, would you mind writing the code đ