forked from pirple/Keeping-Up-With-the-Javascripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions - 2.js
executable file
·61 lines (45 loc) · 951 Bytes
/
Functions - 2.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
57
58
59
60
61
/*
* Functions - 2
*
*/
const users = [
{name: "Chris", age: 60},
{name: "Jane", age: 30},
{name: "Billy", age: 45}
];
const mapUserNames = (myArr) =>
myArr.map((user) => user.age);
function numberMultiplier(x=5, y=10) {
return x * y;
}
const initialString = "How are you?"
function stringSplitter(str=initialString) {
return str.split(" ");
}
const bankAccount = {
canSpendMoney: true,
balance: 100
}
function purchaseItem(price, acct=bankAccount) {
if (acct.canSpendMoney) {
acct.balance -= price;
if (acct.balance <= 0) {
acct.canSpendMoney = false;
}
return true;
} else {
return false;
}
}
function multiply(multiplier, ...nums) {
return nums.map((n) => multiplier * n)
}
function Dog(years, breed) {
this.age = years;
this.type = breed;
setInterval(() => {
this.age += 1;
}, 5000)
}
const spike = new Dog(3, "Golden Retriever");
const fido = new Dog(5, "Poodle");