Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren0
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)
7 Antworten
+ 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 🙏