diff --git a/Lesson_4/task_1.js b/Lesson_4/task_1.js new file mode 100644 index 0000000..7681337 --- /dev/null +++ b/Lesson_4/task_1.js @@ -0,0 +1,19 @@ +function makeObj(val) { + let obj = {}; + if (val <= 999){ + let digit; + let counter = 0 + while (val != 0) { + digit = val % 10; + if (counter == 0) obj['Единицы'] = digit; + else if (counter == 1) obj['Десятки'] = digit; + else obj['Сотни'] = digit; + val = (val - digit) / 10; + counter++; + } + return obj; + } else return obj; +} + +const num = prompt("Введи число от 0 до 999."); +console.log( makeObj(num)); diff --git a/Lesson_4/task_2.js b/Lesson_4/task_2.js new file mode 100644 index 0000000..9eff93c --- /dev/null +++ b/Lesson_4/task_2.js @@ -0,0 +1,23 @@ +const myCart = { + products: [{ + id: 54321, + title: "qwerty", + price: 10000, + count: 2 + }, + { + id: 12345, + title: "asdfgh", + price: 5000, + count: 3 + }], + result() { + let res = 0; + for (i = 0; i < this.products.length; i++) { + res += this.products[i].price * this.products[i].count; + } + return res; + } +}; + +console.log(myCart.result())