Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Lesson_4/task_1.js
Original file line number Diff line number Diff line change
@@ -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));
23 changes: 23 additions & 0 deletions Lesson_4/task_2.js
Original file line number Diff line number Diff line change
@@ -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())