- 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); }
10 Answers
+ 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.
+ 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);
}
+ 2
function main() {
var age = parseInt(readLine(), 10)
// Your code here
console.log(age>=18);
}
Good Luck
+ 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
+ 1
Holy crap i got it now thanks kevin.
0
function main() {
var age = parseInt(readLine(), 10)
// Your code here
if(age >= 18){console.log(true)}else(console.log(false))
}
0
console.log(age>=18);
0
function main() {
var age = parseInt(readLine(), 10)
if (age >= 18) {
console.log(true);
}
else {
console.log(false);
}
}