- 2

How do i separate my values for multiple test cases in javascript comparison operators.

Write a program that takes the age of user as input, checks if the user is adult, and outputs to the console the corresponding boolean value. //This is the code ive written function main() { var age = parseInt(readLine( 10) ) var age = 18; console.log(age === 26); var age = 18; console.log(age === 15);//less than var age = 18; console.log(age === 18); }

24th Nov 2020, 9:22 PM
Emmanuel Riano
Emmanuel Riano - avatar
10 ответов
+ 7
You do not need to change 'age' variable. A separate version of your program will run for each test case, and the respective input (age) is passed via readLine() Try running this code and inspecting the visible tests: function main() { var age = parseInt (readLine(),10) console.log(age) } Now, you have to change this line: console.log(age) According to the problem: "If the user is 18, he is considered as adult." And, for the sake of clearness, users older than 18 years old are adults too. Take a look at the table provided here: https://www.sololearn.com/learn/JavaScript/1132/ And choose the operator that suits better.
24th Nov 2020, 10:00 PM
Kevin ★
+ 4
If the user is 18 or older, they’re considered an adult. console.log(20>18) outputs true. function main() { var age = parseInt(readLine(), 10) // Your code here console.log(age>=18); }
17th Aug 2021, 3:55 PM
M.A.Nisansala Madhushani
M.A.Nisansala Madhushani - avatar
+ 2
function main() { var age = parseInt(readLine(), 10) // Your code here console.log(age>=18); } Good Luck
25th Jan 2022, 8:18 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 2
function main() { var age = parseInt(readLine(), 10) // Your code here age >= 18 ? console.log("true") : console.log("false") } ...that works for me. So.. the code is a bit shorter. age >= 18 // if ? //then execute the code after the ? sign : // else execute the code after the : sign
3rd Feb 2022, 4:54 PM
Loopsen
Loopsen - avatar
+ 1
Holy crap i got it now thanks kevin.
24th Nov 2020, 10:40 PM
Emmanuel Riano
Emmanuel Riano - avatar
0
function main() { var age = parseInt(readLine(), 10) // Your code here if(age >= 18){console.log(true)}else(console.log(false)) }
15th Sep 2021, 6:51 PM
sobhan jaefari
sobhan jaefari - avatar
0
console.log(age>=18);
21st Apr 2022, 5:28 PM
Erhan TEZER
0
function main() { var age = parseInt(readLine(), 10) if (age >= 18) { console.log(true); } else { console.log(false); } }
30th May 2022, 1:15 PM
DAMIAN PSYCHE
DAMIAN PSYCHE - avatar