+ 1

Pls help

Logical or boolean operation "noon or night" exercise. Please teach me how to do it. https://www.sololearn.com/coach/419?ref=app 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 I tried many things but none worked so I need someone to help from scratch. process.stdin.setEncoding('utf-8'); let inputString = ''; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { main(inputString); }); function main(input) { var hour = parseInt(input, 10) // Your code here //This is the provided base for the code }

8th Oct 2020, 6:57 PM
Goutam Chaitanya
Goutam Chaitanya - avatar
7 Respostas
- 1
/*Just in case anyone wants to know, I completed it myself The answer is below*/ process.stdin.setEncoding('utf-8'); let inputString = ''; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { main(inputString); }); function main(input) { var hour = parseInt(input, 10) // Your code here if(hour <=12){ console.log("am") } else{ console.log("pm") } }
9th Oct 2020, 6:13 AM
Goutam Chaitanya
Goutam Chaitanya - avatar
+ 6
Please show us a code you have started with and the linkto the challenge
8th Oct 2020, 6:58 PM
Galaxy-Coding (inactive)
Galaxy-Coding (inactive) - avatar
8th Oct 2020, 7:29 PM
Galaxy-Coding (inactive)
Galaxy-Coding (inactive) - avatar
+ 5
// i got the answer process.stdin.setEncoding('utf-8'); let inputString = ''; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { main(inputString); }); function main(input) { var hour = parseInt(input, 10) var h = input var session = "AM"; if(h == 0){ session="am" } if(h > 12){ h = h - 12; session = "pm"; } console.log(session) }
8th Oct 2020, 8:00 PM
Galaxy-Coding (inactive)
Galaxy-Coding (inactive) - avatar
+ 1
You added it now. Thank for edit. And you got it. Nice.
9th Oct 2020, 2:50 PM
Jayakrishna 🇼🇳
0
The link is private other can't see. Description link is pro link.. Can't see Non-pro members.. So you need to copy paste description and your tried code, if you need.. Edit : Thanks for edit. You did it now..Goutam Chaitanya 👍👍👍
8th Oct 2020, 7:12 PM
Jayakrishna 🇼🇳
0
Jayakrishna🇼🇳 that's why I wrote the question and the base code
9th Oct 2020, 1:54 AM
Goutam Chaitanya
Goutam Chaitanya - avatar