+ 4

Struggle

Can anybody help me with this ? Boolean and logical operators Given a clock that measures 24 hours in a day. Write a program, that takes the hour as input. If the hour is in the range of 0 to 12, output am to the console, and output pm if it's not. Sample Input 13 Sample Output pm

14th Nov 2020, 2:43 AM
Marcel Mucska
Marcel Mucska - avatar
11 odpowiedzi
+ 4
function main() { var hour = parseInt(readLine(), 10); // Your code goes here //you need to use if,else for this problem if(hour>=0 && hour<=12) console.log("am"); if(hour>12 && hour<=24) console.log("pm"); }
17th Jun 2021, 10:43 AM
Sachin KS
+ 3
This is simple. You will not get directly codes here. Also specify programming language hint is given below Hint: //Input hours //Logic of your code if(hours>=0 && hours<=12) print("am"); if(hours>=12 && hours<=24) print("pm"); else print("Maybe you are not on Earth"); https://www.sololearn.com/discuss/1316935/?ref=app
14th Nov 2020, 2:56 AM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 3
But i dont know the if else operations yet
14th Nov 2020, 5:24 AM
Marcel Mucska
Marcel Mucska - avatar
+ 3
i did it a little bit difrent: function main() { var hour = parseInt(readLine(), 10); // Your code goes here var ishour = (hour <= 12 ) ? "am" : "pm" console.log(ishour) }
10th Feb 2022, 3:53 AM
Yago Safini
Yago Safini - avatar
+ 2
If it's 12 then it's pm. So, if hour < 12 is am, and hour >= 12 is pm. Hour must also be a value from 0 to 23. User input of 24 could be changed to 0 in order to enable the code to automatically correct user input so as to "handle" this situation instead of asking the user for only values less than 24. People often consider value of 24 to be strictly equal to 12am. You could use input%12, to set values 12 to 24 to their 12-hour equivalent. But you would need to handle 12 and 24 as pm and am, respectively, since 12%12 and 24%12 are both equal to 0. To pass this challenge it requires that your program account for 13 hours that return am, and for another 12 hours to return pm. But, since this equals 25 hours, the correct answer to the challenge is not logically accurate. Instead of input from 0 to 24, the challenge should require correct output for input from 0 to 23. Humans count hours 1 to 24, therefore 0-index computer counting needs to be 0 to 23. I mean, RIGHT???
13th Jan 2022, 4:11 AM
Andrew Grant Sheppard
Andrew Grant Sheppard - avatar
+ 2
hour=(hour>=0 && hour<=11)?console.log("am"): console.log("pm")
2nd Sep 2023, 8:24 AM
Rupali Mandlik
Rupali Mandlik - avatar
+ 1
if(hour >=0 && hour <= 12){console.log("am")}else(console.log("pm"))
15th Sep 2021, 6:57 PM
sobhan jaefari
sobhan jaefari - avatar
0
Think of it like this: if the variable is higher or equal to 0 and lower or equal to 12 then it's am. if the variable is higher to 12 and lower or equal to 24 then it's pm. (putting things like this helps me to follow the logic of the code) Hope it helps!
25th Aug 2021, 3:15 PM
Ricardo Pereira
Ricardo Pereira - avatar
0
function main() { var hour = parseInt(readLine(), 10); // Your code goes here //you need to use if,else for this problem if(hour>=0 && hour<=12) console.log("am"); if(hour>12 && hour<=24) console.log("pm"); } Good Luck
25th Jan 2022, 3:15 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
let hour = parseInt(readLine(), 10); //your code goes here if(hour>=0 && hour<12) console.log("am"); if(hour>=12 && hour<=24) console.log("pm");
8th Sep 2023, 8:02 AM
RITIK KUMAR
RITIK KUMAR - avatar
0
why is this wrong? var month = "september" if (month == "Agosto") { console. log ("vacación") }
1st Jan 2024, 11:56 PM
Alejandro