+ 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)

9th Oct 2021, 7:10 PM
Isabelle Ostoic
Isabelle Ostoic - avatar
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 ).
9th Oct 2021, 11:42 PM
zexu knub
zexu knub - avatar
+ 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
10th Oct 2021, 5:38 AM
Nino
Nino - avatar
+ 2
No yet, but thanks, I'll try again.
9th Oct 2021, 9:00 PM
Isabelle Ostoic
Isabelle Ostoic - avatar
+ 2
Thanks, but I have completed this challenge, a solohelper helped me.
9th Oct 2021, 11:44 PM
Isabelle Ostoic
Isabelle Ostoic - avatar
+ 1
It's not working
9th Oct 2021, 7:34 PM
Isabelle Ostoic
Isabelle Ostoic - avatar
+ 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...
9th Oct 2021, 7:37 PM
Paul K Sadler
Paul K Sadler - avatar
+ 1
9th Oct 2021, 11:46 PM
zexu knub
zexu knub - avatar
0
Did you get it working 💪?
9th Oct 2021, 8:42 PM
Paul K Sadler
Paul K Sadler - avatar
- 1
Isa Play console.log(age>=18) ...not main The variable is age var age = ...
9th Oct 2021, 7:27 PM
Paul K Sadler
Paul K Sadler - avatar