-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
56 lines (46 loc) · 1.34 KB
/
functions.js
File metadata and controls
56 lines (46 loc) · 1.34 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
45
46
47
48
49
50
51
52
53
54
55
56
//Activity 1:
//Take this code and turn it into arrow function syntax:
const factorial = (n) => {
if ((n === 0) || (n === 1)) {
return 1;
} else {
return (n * factorial (n-1));
}
}
console.log(factorial(33));
//Activity 2:
//Edit the below snippet to include two parameters and a running order count updated
//when the function is called:
let orderCount = 0;
const takeOrder = (topping,base) => {
console.log (`Pizza with ${topping} and ${base}`);
orderCount = orderCount + 2;
}
takeOrder ('pineapple','tomato');
//Activity 3:
//Cash machine time! Let’s create one that:
//> Dispenses cash if your pin number is correct and your balance is equal to, or more than,
//the amount you’re trying to withdraw!
const account = {
pin: "5432",
balance: 300.25
}
const withdraw = (pin,amount) => {
if (amount < 0) {
console.log("You cannot withdraw a negative amount");
return;
}
if (pin === "5432") {
if (amount < account.balance) {
account.balance = account.balance - amount;
console.log(`Withdrew ${amount}, now have ${account.balance} remaining.`)
} else {
console.log("Insufficient funds")
}
} else {
console.log("Incorrect pin number")
}
}
withdraw("5432",20);
withdraw("1234",20);
withdraw("5432",400);