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...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a...
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...
Define a function in Javascript named secondHighest which accepts an array of numbers, and returns the...
Define a function in Javascript named secondHighest which accepts an array of numbers, and returns the second highest number from the array. If the highest value occurs more than once, then it is also the second highest (see example). Assume the input array will always have length at least two (so there is always a second highest value). The original array must NOT be modified by this function. Example secondHighest([5,3,8,6,2,7,4]) must return 7, and secondHighest([5,3,8,6,2,7,8]) must return 8. I have...
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...
In the funcs directory create a file named funcs.py. This section requires that you implement and...
In the funcs directory create a file named funcs.py. This section requires that you implement and test multiple functions. You should develop these functions and their tests one at a time. The function implementations must be placed in funcs.py. The test cases will, of course, be placed in the provided funcs_tests.py. You must provide at least two test cases for each of these functions. In addition, you should separate your testing into multiple functions (the file includes stubs for the...
Please use Python! def getText(file): This function should open the file named file, and return the...
Please use Python! def getText(file): This function should open the file named file, and return the contents of the file formatted as a single string. During processing, you should (i) remove any blank lines, (ii) remove any lines consisting entirely of CAPITALIZED WORDS , and (iii) replace any explicit ’\n’ (newline) characters with spaces unless directly preceeded by a ’-’ (hyphen), in which case you should simply remove both the hyphen and the newline, restoring the original word. def getText(file):...
JavaScript Write a function named "reverse_kvs" that has a key-value store as a parameter and returns...
JavaScript Write a function named "reverse_kvs" that has a key-value store as a parameter and returns a new key-value store. Your function should add each key-value pair in the parameter to the new key-value store EXCEPT reversing the key and value. For example, if the key-value "extreme":45 were in the parameter then the returned key-value store should contain the key-value pair 45:"extreme". Code: function reverse_kvs(store) { var reverse_store = {}; for (var key in store) { if (store.hasOwnProperty(key)) { reverse_store[store[key]]...
Using JavaScript for the following assignment Design and code a function named "intersection" that takes two...
Using JavaScript for the following assignment Design and code a function named "intersection" that takes two arrays of numbers in parameter and returns a new array containing only the values that are both in the two arrays. A value must not be found more than once in the resulting array but can be found more than once in the arrays in parameter. The order of the elements in the resulting array must respect the order of the first parameter. For...
Define a JavaScript function named prepend that has two parameters. The first parameter is an array...
Define a JavaScript function named prepend that has two parameters. The first parameter is an array of Strings. The second parameter is a String. Your function should use the accumulator pattern to return a newly created array whose elements are the concatenation of the second parameter with the element at the same index in the first parameter.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT