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

4th Oct 2021, 5:12 AM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
4 Respostas
+ 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); }
4th Oct 2021, 6:10 AM
Ipang
+ 1
Tahiti, Check now, I've updated it to include the main() function.
4th Oct 2021, 12:44 PM
Ipang
+ 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 !
4th Oct 2021, 5:38 PM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar
0
Ipang That code gave a syntax error when I tried it.
4th Oct 2021, 12:27 PM
Tahiti🌍Castillo
Tahiti🌍Castillo - avatar