Skip to content
Open
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
67 changes: 67 additions & 0 deletions Lesson4
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
//Задание №1
function createObject(num) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это задание можно сделать прям в разы проще и современнее)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Был рад додуматься до иного решения(

num = +prompt("Введите число от 0 до 999");
let sap = {
"units": num,
"profs": num,
"hundrds": num
}
sap["hundrds"] = num % 10 * 100;
sap["profs"] = num % 100 % 10 * 10;
sap["units"] = num % 10;
console.log (sap);
}
createObject ()

//Задание №2
let PRODUCT_NAMES = ['Processor', 'Display', 'Notebook', 'Mouse', 'Keyboard']
let PRICES = [100, 120, 1000, 15, 18]
let IDS = [0, 1, 2, 3, 4]

let products = []

let cart = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Меня больше пугает, что вы TAB не используете для того, чтобы код читабельнее сделать :(

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Косяк, согласен, каюсь, учту.

items: [],
total: 0,
addProduct: function getData () {
for (let i = 0; i < IDS.length; i++) {
cart.push (addProduct (i))
}
}

function getData () {
for (let i = 0; i < IDS.length; i++) {
products.push (createNewProducts (i))
}
}

function createNewProducts (index) {
return {
product_name: PRODUCT_NAMES [index],
price: PRICES[index],
product_id: IDS[index]
}
}

function addProduct (id) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Очень хорошая реализация. По-моему вы прибедняетесь, говоря, что не ведаете =)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По правде сказать ,я поступил так от безысходности.
Мне казалось, что эта идея абсурдна и неверна.

let find = products.find (el => el.product_id === id) // Метод поиска по объекту
cart.items.push (Object.assign ({}, find, {quantity: 1}))
}

</script>



</script>
</body>
</html>