-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson4 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Lesson4 #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) { | ||
| 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 = { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Меня больше пугает, что вы TAB не используете для того, чтобы код читабельнее сделать :(
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Очень хорошая реализация. По-моему вы прибедняетесь, говоря, что не ведаете =)
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это задание можно сделать прям в разы проще и современнее)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Был рад додуматься до иного решения(