diff --git a/hw5-1code.js b/hw5-1code.js new file mode 100644 index 0000000..a5e63bc --- /dev/null +++ b/hw5-1code.js @@ -0,0 +1 @@ +renderer.render(); diff --git a/hw5-1main.html b/hw5-1main.html new file mode 100644 index 0000000..d45b872 --- /dev/null +++ b/hw5-1main.html @@ -0,0 +1,14 @@ + + + + + + + + Document + + + + + + diff --git a/hw5-1renderer.js b/hw5-1renderer.js new file mode 100644 index 0000000..3c8e00a --- /dev/null +++ b/hw5-1renderer.js @@ -0,0 +1,33 @@ +let renderer = { + render() { + let table = this.generateTable(); + document.body.insertAdjacentHTML('afterbegin', table); + }, + + generateTable() { + let letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']; + let numbers = ['1', '2', '3', '4', '5', '6', '7', '8']; + let board = ''; + + for (let i = 0; i < 1; i++) { + board += ''; + for (let j = 0; j < letters.length; j++) { + board += ''+ letters[j] + ''; + } + board += ''; + } + + for(let y = 0; y < numbers.length; y++) { + board += ''; + for(let x = 0; x < numbers.length; x++) { + + board += ''; + } + + board += '' + numbers[y] + '' + ''; + + } + + return '' + board + '
'; + }, +} diff --git a/hw5-1style.css b/hw5-1style.css new file mode 100644 index 0000000..e42729f --- /dev/null +++ b/hw5-1style.css @@ -0,0 +1,36 @@ +html { + background: lightgrey; +} + +table { + border-collapse: collapse; +} + +td { + width: 30px; + height: 30px; + border: 2px solid black; +} + +tbody tr:nth-child(2n + 1) td:nth-child(2n) { + background: black; +} + +tbody tr:nth-child(2n) td:nth-child(2n+1) { + background: black; +} + +.with_letters > td { + background-color: transparent !important; + width: 30px; + height: 30px; + text-align: center; + border: none; +} + +.with_numbers { + background-color: transparent !important; + border: none; + text-align: center; +} + diff --git a/hw5-2basket.js b/hw5-2basket.js new file mode 100644 index 0000000..45b70dc --- /dev/null +++ b/hw5-2basket.js @@ -0,0 +1,26 @@ +let basketGeneration = { + generate() { + let empty = this.generateEmptyBasket(); + document.body.insertAdjacentHTML('afterbegin', empty); + + let list = this.generateFullList(); + document.body.insertAdjacentHTML('afterbegin', list); + }, + + generateEmptyBasket() { + empty = 'Ваша карзина пуста'; + return empty; + }, + + generateFullList() { + list = ''; + for (let i = 0; i < basket.goodlist.length; i++) { + list += '
  • ' + JSON.stringify(basket.goodlist[i].name) + '\n' + JSON.stringify(basket.goodlist[i].price) + ' рублей. ' + '\n' + JSON.stringify(basket.goodlist[i].amount) + ' шт.' + '
  • '; + } + list += '

    Всего в вашей карзине ' + basket.countTotalNumber() + ' товара. На сумму: ' + basket.countTotalPrice() + ' рублей.'; + return ''; + }, +} + + + diff --git a/hw5-2box.js b/hw5-2box.js new file mode 100644 index 0000000..dada1e2 --- /dev/null +++ b/hw5-2box.js @@ -0,0 +1,20 @@ +let basket = { + goodlist: [], + + countTotalPrice() { + var priceSum = 0; + for (i in this.goodlist) { + let finalPrice = this.goodlist[i].price * this.goodlist[i].amount; + priceSum += finalPrice; + } + return priceSum; + }, + + countTotalNumber() { + let totalNum = 0; + for (i in this.goodlist) { + totalNum += this.goodlist[i].amount; + } + return totalNum; + } +} diff --git a/hw5-2code.js b/hw5-2code.js new file mode 100644 index 0000000..058c48a --- /dev/null +++ b/hw5-2code.js @@ -0,0 +1 @@ +basketGeneration.generate(); diff --git a/hw5-2goods.js b/hw5-2goods.js new file mode 100644 index 0000000..e74af0e --- /dev/null +++ b/hw5-2goods.js @@ -0,0 +1,69 @@ +let goods = [ + { + name: 'лампа', + price: 1200, + amount: 4, + putToBasket() { + basket.goodlist.push(this); + } + }, + { + name: 'диван', + price: 25000, + amount: 1, + putToBasket() { + basket.goodlist.push(this); + } + }, + { + name: 'тумба', + price: 4500, + amount: 2, + putToBasket() { + basket.goodlist.push(this); + } + }, + { + name: 'зеркало', + price: 5000, + amount: 4, + putToBasket() { + basket.goodlist.push(this); + } + }, + { + name: 'шкаф', + price: 35000, + amount: 1, + putToBasket() { + basket.goodlist.push(this); + } + }, + { + name: 'туалетный столик', + price: 7000, + amount: 2, + putToBasket() { + basket.goodlist.push(this); + } + }, + { + name: 'пуфик', + price: 2000, + amount: 2, + putToBasket() { + basket.goodlist.push(this); + } + } +] + +console.log(goods); +goods.forEach(function(item, i) { + if (i % 2 == 0) { + item.putToBasket(); + } else { + item.putToBasket(); + item.putToBasket(); + } +}); + diff --git a/hw5-2main.html b/hw5-2main.html new file mode 100644 index 0000000..d0cc740 --- /dev/null +++ b/hw5-2main.html @@ -0,0 +1,19 @@ + + + + + + + + + Document + + + + + + + + + + diff --git a/hw5-2style.css b/hw5-2style.css new file mode 100644 index 0000000..3c78067 --- /dev/null +++ b/hw5-2style.css @@ -0,0 +1,3 @@ +html { + background: darkseagreen; +}