-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample3.js
More file actions
44 lines (33 loc) · 1.41 KB
/
example3.js
File metadata and controls
44 lines (33 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Description: This program is calculating the amount of change given to the customer after buying groceries but there is a bug
* in the code preventing the code to run as expected. Your task is to run and debug the program using the console to print
* statements.
*
* TODO: The program currently displays NaN in the console as the returned change. You should check and make sure the function
* is reading the passed parameters.
*/
function checkPoint3(){
alert4();
function superMarket(cash) {
let milk = 4.99;
let vegetables = 15.99;
let bread = 2.99;
let total = milk + vegetables + bread;
cash = cash - total;
return cash;
}
function main(cash) {
let moneySpent = superMarket(cash); // Added cash as argument here
return moneySpent;
}
let totalCash = 50.00;
console.log("Total Cash: $" + totalCash);
console.log("Change Return = $" + main(totalCash));
if (main(totalCash) < 50) {
alert("Awesome work! You got the system running!");
}
}
/************************************************ DON'T EDIT THE CODE BELOW ******************************************************/
function alert4() {
alert("The system at the supermarket doesn't seem to be working. Can you help debug the system to help calculate the total change return to the customer? Go to the example3.js file and work on checkpoint 3.");
}