W2P1 done
This commit is contained in:
parent
c9ee8f17db
commit
7908f6eb2e
2 changed files with 51 additions and 0 deletions
38
w2/p1/app.js
Normal file
38
w2/p1/app.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const fruits = [
|
||||||
|
{ name: "apple", count: 5, price: 70 },
|
||||||
|
{ name: "orange", count: 10, price: 90 },
|
||||||
|
{ name: "pineapple", count: 15, price: 110 },
|
||||||
|
{ name: "watermelon", count: 20, price: 130 },
|
||||||
|
{ name: "cherry", count: 25, price: 150 },
|
||||||
|
{ name: "pear", count: 30, price: 170 },
|
||||||
|
{ name: "peach", count: 35, price: 190 },
|
||||||
|
];
|
||||||
|
|
||||||
|
// Сюда бы reduce...
|
||||||
|
const bill1 = {
|
||||||
|
bill: fruits,
|
||||||
|
result: (() => {
|
||||||
|
let sum = 0;
|
||||||
|
for (let i = 0; i < fruits.length; i++) {
|
||||||
|
sum += fruits[i].count*fruits[i].price;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify(bill1));
|
||||||
|
|
||||||
|
// Подсчёт суммы forEach'ем
|
||||||
|
const bill2 = {
|
||||||
|
bill: fruits,
|
||||||
|
result: (() => {
|
||||||
|
let sum = 0;
|
||||||
|
fruits.forEach(fruitO => sum += fruitO.count*fruitO.price);
|
||||||
|
return sum;
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify(bill2));
|
||||||
|
|
||||||
|
// Выведем ещё и дату
|
||||||
|
console.log(`Сегодня ${new Date().toLocaleDateString("ru-RU", {weekday: "long", year: "numeric", month: "2-digit", day: "2-digit"})}`);
|
||||||
13
w2/p1/index.html
Normal file
13
w2/p1/index.html
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Пожалуйста, откройте DevTools <noscript>и включите javascript</noscript>
|
||||||
|
</body>
|
||||||
|
<script src="./app.js"></script>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue