+ 5

What's is the Output of this code different from what I expected?

var age = 42; var isAdult = (age < 18) ? "Too young": "Old enough"; document.write(isAdult); Isn't the output supposed to be "Too young" according to the statement when age is less than 18. But I'm seeing "Old enough" as the output. Now I'm confused. Pls help guys

23rd Jun 2020, 8:38 AM
Cyber Nate 👨🏻‍💻
Cyber Nate 👨🏻‍💻 - avatar
3 Answers
+ 2
Read that line as follows ... if age less than 18 then let isAdult value be "Too young" else let isAdult value be "Old enough"
23rd Jun 2020, 8:45 AM
Ipang
+ 4
Oh I understand now! And age is 45 whereby greater than 18. Thanks so much
23rd Jun 2020, 9:05 AM
Cyber Nate 👨🏻‍💻
Cyber Nate 👨🏻‍💻 - avatar
- 1
The value of age already is 42,which is greater than 18 in normal terms Soo the output is too young
23rd Jun 2020, 12:39 PM
Vic Okeke