Control Flow in R and IF Statements Module

How does this code accounts for ages not over 21?

But if age is 18+ but not 21+, you have to check whether the current_hour is earlier than 11. If it is, you can set access_event to TRUE and you should print "I can stay until 11!“ Hint: you can either nest the first check into the second, or use an & (AND) operator to combine them.

If age is not 18+ or 21+, both access_event and access_music_show should stay FALSE and you should print “I guess I’ll go somewhere else.”

write your conditionals code here:

if (age >= 21) {
access_event <- TRUE
print(“I got into the event for the night!”)
if (possible_codeword == real_codeword) {
access_music_show <- TRUE
print(“I need to get a good spot!”)
} else if (age >= 18 & current_hour < 11) {
access_event <- TRUE
print(“I can stay until 11!”)
} else {
print(“I guess I’ll go somewhere else.”)

Hello @codezena2452328029, welcome to the forums!

This code checks to see if the age is greater than or equal to, 21. Since it gets evaluated first, and the other control statements that are on its nesting level are not if, if this line is TRUE, none of these lines will run:

However, if the age is less than 21, the else if line evaluates. This will only check its condition if this if is FALSE:

Lastly, if neither the if or else if condition (the bit inside the parentheses-if (condition)), the else runs.

I hope this helps!