0
Logical or Boolean Operators
//On a 24-hour clock, output either am or pm, depending on the hour. // I entered: function main() { var hour = parseInt(readLine(), 10); // Your code goes here var hour = ("<= 12") ? "am": "pm"; console.log(hour); } /* Test case (failed) used 14 as input and returned “am”. Why? I used the exact formula given in the lesson: variable = (condition) ? value1: value2 Ex: var isAdult = (age<18) ? “Too young”: “Old enough”; */ // https://sololearn.com/discuss/2896745/?ref=app
4 odpowiedzi
+ 2
AM or PM is only used for 12-hour time, 24-hour time doesn't use that.
Your way for checking should be ...
function main()
{
var hour = parseInt(readLine(), 10);
// Your code goes here
var amOrPm = (hour<= 12) ? "am": "pm";
console.log(amOrPm);
}
+ 1
Tahiti,
Check now, I've updated it to include the main() function.
+ 1
function main() {
var hour = parseInt(readLine(), 10);
// Your code goes here
var meridiem = (hour <=12) ? "am": "pm";
console.log(meridiem);
}
// This similar code worked also. Thank you Ipang !
0
Ipang That code gave a syntax error when I tried it.