-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshoppinglist.js
81 lines (77 loc) · 1.63 KB
/
shoppinglist.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const shoppingItems = [
{
id: 1,
name: "milk",
date: "2021-10-07",
price: 2.50,
need: true,
},
{
id: 2,
name: "bread",
date: "2021-10-07",
price: 2,
need: false,
},
{
id: 3,
name: "eggs",
date: "2021-10-07",
price: 5,
need: true,
},
{
id: 4,
name: "sandwhich meat",
date: "2021-10-07",
price: 8,
need: true,
},
{
id: 5,
name: "watermelon",
date: "2021-10-07",
price: 3,
need: false
}
]
const addToShoppingItems = (listObject) => {
const lastIndex = shoppingItems.length - 1
const currentLastItem = shoppingItems[lastIndex]
const maxId = currentLastItem.id
const newId = maxId + 1
listObject.id = newId
listObject.date = new Date()
shoppingItems.push(listObject)
}
addToShoppingItems({
name: "strawberries",
date: "2021-10-07",
price: 4,
need: true,
})
addToShoppingItems({
name: "blueberries",
date: "2021-10-07",
price: 8,
need: false,
})
addToShoppingItems({
name: "melons",
date: "2021-10-07",
price: 10,
need: false,
})
addToShoppingItems({
name: "steak",
date: "2021-10-07",
price: 16,
need: true,
})
for (const shoppingItem of shoppingItems) {
if(shoppingItem.price >= 8){
console.log(`The ${shoppingItem.name} is too much for you`)
}
else{
console.log(`You might be able to get these ${shoppingItem.name}`)
}}