-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfuncPr-practice.html
More file actions
47 lines (41 loc) · 1.31 KB
/
Copy pathfuncPr-practice.html
File metadata and controls
47 lines (41 loc) · 1.31 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
const cart = [
{ item: "노트북", price: 1200000, quantity: 1 },
{ item: "마우스", price: 35000, quantity: 2 },
{ item: "키보드", price: 89000, quantity: 1 }
];
let totalPrice = 0;
for (let i=0; i<cart.length; i++) {
totalPrice += (cart[i].price * cart[i].quantity);
}
console.log(`Total Price: ${totalPrice}`);
totalPrice = 0;
cart.forEach(product => {
totalPrice += product.price * product.quantity;
});
console.log(`Total Price: ${totalPrice}`);
totalPrice = cart.reduce(
(a, product) => (a + product.price * product.quantity), 0
);
console.log(`Total Price: ${totalPrice}`);
const itemTotals = cart.map(product => ({
item: product.item,
total: product.price * product.quantity
}));
console.log('제품별 금액: ',itemTotals);
const names = ['alice', 'bob', 'charlie'];
const uppercasedNames = names.map(lowName => lowName.toUpperCase());
console.log(`[ ${uppercasedNames} ]`);
const capitalStartnames = names.map(initName => initName[0].toUpperCase() + initName.slice(1));
console.log(`[ ${capitalStartnames} ]`);
</script>
</body>
</html>