+ 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
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");
}
+ 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
+ 3
But i dont know the if else operations yet
+ 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)
}
+ 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???
+ 2
hour=(hour>=0 && hour<=11)?console.log("am"): console.log("pm")
+ 1
if(hour >=0 && hour <= 12){console.log("am")}else(console.log("pm"))
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!
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
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");
0
why is this wrong?
var month = "september"
if (month == "Agosto") {
console. log ("vacación")
}