diff --git a/w2/p1/app.js b/w2/p1/app.js new file mode 100644 index 0000000..ef5c8e5 --- /dev/null +++ b/w2/p1/app.js @@ -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"})}`); diff --git a/w2/p1/index.html b/w2/p1/index.html new file mode 100644 index 0000000..3382d1f --- /dev/null +++ b/w2/p1/index.html @@ -0,0 +1,13 @@ + + + + + + + Document + + + Пожалуйста, откройте DevTools + + + \ No newline at end of file