Question

In: Computer Science

(Javascript) Modify the JavaScript file to implement a function named calculateTotalPrice. At the bottom of the...

(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));

Solutions

Expert Solution

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.


Related Solutions

USING JAVASCRIPT Create a file name dayOfWeek.js and write an arrow function named dayOfWeek that accepts...
USING JAVASCRIPT Create a file name dayOfWeek.js and write an arrow function named dayOfWeek that accepts a Date object dateStr and returns a string that is the day of the week in English form (i.e. “Sunday”, “Monday”, etc.). Test your function by creating a date object that is a significant date to you (such as your birthday) and passing that date object to your function. Test your function at least twice with two different dates. Submit the dayOfWeek.js file to...
Python, filing and modules Modify the driver to write the statistics to a file named employee-stats.txt...
Python, filing and modules Modify the driver to write the statistics to a file named employee-stats.txt rather than to the console. driver.py code: from employee import Employee employees = [] # Load an employee object for each employee specified in 'employees.txt' into the employees list. employee.txt Jescie Craig VP 95947 Marny Mckenzie Staff 52429 Justin Fuller Manager 72895 Herman Love VP 108204 Hasad Wilkins Staff 96153 Aubrey Eaton Staff 76785 Yvonne Wilkinson Staff 35823 Dane Carlson Manager 91524 Emma Tate...
Implement a function named printRange that, given the pointer to the root of a BST, a...
Implement a function named printRange that, given the pointer to the root of a BST, a low key value, and a high key value, prints in sorted order all records whose key values fall between the two given keys (inclusive). Function printRange should visit as few nodes in the BST as possible. Here is the start code (in Java 8) for this problem. Input Format Three lines. The first line includes the number of keys to be put in the...
Complete the function main in file median.c to implement the computation of the median of a...
Complete the function main in file median.c to implement the computation of the median of a sequence of integers read from stdin. The program should use realloc to allow an arbitrary number of integers to be read into a dynamically allocated array. Every time realloc is called, let the new size of the array be twice the old size plus 1. Look at function readLongLine in the slides for Chapter 6 for an example of how to use realloc. The...
Invent a recursive function and save the program in a file named " q3c.java” It should...
Invent a recursive function and save the program in a file named " q3c.java” It should not be any of the familiar ones (like fibonacci or binomial coefficients or any of those). Make one up. Make sure it is well-defined (no ambiguity), make sure it isn’t “infinitely recursive”. • Implement it in a Java program and demonstrate it with at least 7 test values. • Add necessary comments to the program to explain it. • In comments, describe your test...
Problem Statement: Implement the MyString class using a header and implementation file named MyString.h and MyString.cpp...
Problem Statement: Implement the MyString class using a header and implementation file named MyString.h and MyString.cpp respectively. Make sure to properly test your code on your own by creating a test driver that tests every function created in the MyString class. Deliverables: proj3-MyString.h proj3-MyString.cpp proj3-testMain.cpp Memory Requirements: Your MyString should start with 10 bytes of allocated memory and should grow in size by doubling. So, we should be able to predict the capacity of your MyString as acquiring a patten...
II. Big Numbers 1. Implement this program in a file named bigNums.py. 2. Create a numerical...
II. Big Numbers 1. Implement this program in a file named bigNums.py. 2. Create a numerical (integer) list, named numbers. Populate the list with 1,000,000 (one million) integer values with values from 0 to 999,999. Hint: Use the range() function. 3. Print the length of the list to the screen. Ensure you have 1,000,000 items in your list. Hint: Use the len() function. 4. Print the smallest item value in the list to the screen. Hint: use the min() function....
Define a JavaScript function named showBins which has one parameter which is a JSON blob (JSON...
Define a JavaScript function named showBins which has one parameter which is a JSON blob (JSON encoding). The parameter encodes an array of Numbers. Your function should display the value at index 0 of the array in a text element whose id is "small", display the value at index 1 of the array in a text element whose id is "med", and display the value at index 2 of the array in a text element whose id is "large".
You should assume that there will be an object file named “foreignsub.o” which implements a function...
You should assume that there will be an object file named “foreignsub.o” which implements a function whose prototype is given in the header file “foreignsub.h”. The header file “foreignsub.h” consists of the following line. int sub(int n, int *A, int *B, int *C); However, you do not know what this function does exactly. For your testing purpose, you may produce such a function, e.g., returning the maximum value among the 3n integers in the three arrays. You are also given...
Implement a function that reads numbers in from a file with one number per line and...
Implement a function that reads numbers in from a file with one number per line and outputs all the possible sums that can be formed by subsets of the numbers. For instance, if the numbers in the file are 1 2 4, then the output would be 0, 1, 2, 4, 3, 5, 6, 7. Note that 0 is in the output because it uses none of the numbers, while 7 is the sum of all of the numbers. //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT