In: Computer Science
(Javascript) Modify the JavaScript file to implement a function named calculateTotalPrice. At the bottom of the file are sample inputs and outputs to test your implementation.
/*
* The price per ticket depends on the number of tickets
* purchased, there are 4 ticket pricing tiers. Given the
* number of tickets return the total price, formatted to
* exactly two decimal places with a leading dollar sign.
* Tier 1:
* Minimum number of tickets: 1
* Price per ticket: $16.75
* Tier 2:
* Minimum number of tickets: 4
* Price per ticket: $14.00
* Tier 3:
* Minimum number of tickets: 7
* Price per ticket: $11.00
* Tier 4:
* Minimum number of tickets: 11
* Price per ticket: $8.50
*/
function calculateTotalPrice(numberOfTickets) {
//YOUR CODE STARTS HERE
//YOUR CODE ENDS HERE
}
// $33.50
console.log(calculateTotalPrice(2));
// $56.00
console.log(calculateTotalPrice(4));
// $99.00
console.log(calculateTotalPrice(9));
// $110.50
console.log(calculateTotalPrice(13));
function calculateTotalPrice(numberOfTickets) { var price = 0 if(numberOfTickets >= 11) { price = numberOfTickets * 8.50 } else if(numberOfTickets >= 7) { price = numberOfTickets * 11.00 } else if(numberOfTickets >= 4) { price = numberOfTickets * 14.00 } else { price = numberOfTickets * 16.75 } return '$' + price.toFixed(2); }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.