Microsoft
98-382 · Question #40
You are using JavaScript to create a function that calculates admission price. The function must meet the following requirements: ⇨ The function accepts the age of the customer as a parameter ⇨ A…
function ticketPrice(age) { var price = 20; if (age < 5 || age >= 65) { price = 0; } if (age >= 5 && age < 18) { price = 10; } return price; }
Implementing Flow Control
Question
You are using JavaScript to create a function that calculates admission price. The function must meet the following requirements:
⇨ The function accepts the age of the customer as a parameter
⇨ A customer who is less than 5 years old gets in free
⇨ A customer who is 65 years old or older gets in free
⇨ A customer who is 5 years old to 17 years old, pays $10 USD
⇨ All other customers pay $20 USD
How should you complete the code? To answer, select the appropriate code segments in the answer area. NOTE: Each correct selection is worth one point.
Explanation
function ticketPrice(age) { var price = 20;
if (age < 5 || age >= 65) { price = 0; }
if (age >= 5 && age < 18) { price = 10; }
return price; }
Topics
#if/else#conditional logic#functions#comparison operators
Community Discussion
No community discussion yet for this question.