Answer:
a. a minor on Friday with the discount code
Step-by-step explanation:
Let's try and decipher the given code segment
Let's first look at the if part
if (age <= 18 && day != "Saturday" && day != "Sunday") {
price = price / 2;
==> if a minor and a weekend then price is half = $5
Now look at the else part
else if (day == "Friday" && discountCode == "FREEFRIDAY"){
price = 0;
}
This means if the visitor is NOT a minor and it is NOT a weekend if it is a friday, with a coupon then admission is free
Let's look at the answer choices and see what the logic flow is:
a. minor on Friday with the discount code
if (age <= 18 && day != "Saturday" && day != "Sunday")
All three parts of this condition are true so the statement price = price/2 is executed and price = 5. However, everyone with this coupon should get in free. So this part is incorrectly coded
b. an adult on Friday with the discount code
if part is False, else if part is true and price = 0 which is consistent
c. an adult on the weekend
if part is false, else if part is also false so price printed out is 10 which is consistent
d. a minor on the weekend
the if part is false and so is the else if part , so price is unchanged at 10. Consistent
e. an adult on a weekday
Both the if and else if parts are false, so price is unchanged at 10. COnsistent