-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiptMaker.js
56 lines (53 loc) · 1.34 KB
/
receiptMaker.js
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
45
46
47
48
49
50
51
52
53
54
55
56
// Given variables
const dishData = [
{
name: "Italian pasta",
price: 9.55
},
{
name: "Rice with veggies",
price: 8.65
},
{
name: "Chicken with potatoes",
price: 15.55
},
{
name: "Vegetarian Pizza",
price: 6.45
},
]
const tax = 1.20;
// Implement getPrices()
function getPrices(taxBoolean) {
for(let i = 0; i < dishData.length; i++){
let finalPrice
if(taxBoolean === true){
finalPrice = dishData[i]['price'] * tax
} else if(taxBoolean === false){
finalPrice = dishData[i]['price']
} else {
console.log("You need to pass a boolean to the getPrices call!")
return
}
console.log("Dish: " + dishData[i]['name'] +" Price: $" + finalPrice)
}
}
// Implement getDiscount()
function getDiscount(taxBoolean, guests) {
getPrices(taxBoolean)
if (typeof guests == "number" && guests > 0 && guests < 30){
let discount = 0
if(guests < 5){
discount = 5
} else {
discount = 10
}
console.log('Discount is: $' + discount)
} else {
console.log('The second argument must be a number between 0 and 30')
}
}
// Call getDiscount()
console.log(getDiscount(true, 2));
console.log(getDiscount(false, 10));