+ 3
Input > 18?
Problem: You are given a program that takes the age of the user as input. Complete the code to check if the user is an adult, and output to the console the corresponding boolean value. Sample Input: 20. Sample Output: true. If the user is 18 or older, they’re considered an adult. console.log(20>18) outputs true. My code: function main() { var age = parseInt(readLine(), 10) } console.log(main>=18) Help...(JavaScript)
9 Respuestas
+ 1
function main() {
var age = parseInt(readLine(), 10)
return age;
}
console.log(main() >= age)
#Mistakes
1. Not returning the value of age variable from the main function.
2. Not using main() for calling the main function.( By writing main JS interpreter will think of it as a variable not a function call ).
+ 3
//You can do it this way:
function main() {
var age = parseInt(readLine(), 10)
// Your code here
console.log(age >= 18)
}
//Use the console.log inside the function
+ 2
No yet, but thanks, I'll try again.
+ 2
Thanks, but I have completed this challenge, a solohelper helped me.
+ 1
It's not working
+ 1
What is it doing or not doing that makes you say it's not working? Are you getting an error? If so, look at it carefully and see what it is telling you. Are you not getting the output you expect, or no output at all? If so, look carefully at your code.
So since you have a main function you have to call it for it to execute. main()
}
main() <-- calls the main function
console.log...
you could also just remove the main function and have
var age = ...
console.log...
+ 1
Isa Play Okay
0
Did you get it working 💪?
- 1
Isa Play console.log(age>=18) ...not main
The variable is age
var age = ...