218k views
4 votes
Write an expression that will cause the following code to print "I am a teenager" if the value of userAge is less than 20. Zybooks won't let me edit any other line, and UserAge > 20 was marked wrong. It won't accept the ≥ symbol either.

Write an expression that will cause the following code to print "I am a teenager-example-1

1 Answer

3 votes

Answer:

Replace

if userAge > 20

with

userAge > 19

Step-by-step explanation:

if userAge > 20 checks if age is 21, 22, 23, 24........

The else condition which prints "I am a teenager" checks if age is 20, 19, 18....

Notice that 20 is inclusive of the else condition; this shouldn't be because for userAge to be less than 20, 20 isn't inclusive

To solve this,

Replace if userAge > 20 with userAge > 19

So that, the else

The else condition which prints "I am a teenager" checks if age is 19, 18, 17, 16....

User Theron Luhn
by
6.1k points