diff --git "a/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/code.js" "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/code.js" new file mode 100644 index 0000000..bdb2e7d --- /dev/null +++ "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/code.js" @@ -0,0 +1 @@ +generator.generateGoodsList(); diff --git "a/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/config.js" "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/config.js" new file mode 100644 index 0000000..ce0bb96 --- /dev/null +++ "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/config.js" @@ -0,0 +1,4 @@ +config = { + rows: 7, + cols: 4 +} diff --git "a/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/functions.js" "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/functions.js" new file mode 100644 index 0000000..3a558ce --- /dev/null +++ "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/functions.js" @@ -0,0 +1,15 @@ +function increment(event) { + let input = event.target.previousSibling; + let currentValue = Math.floor(input.value); + input.value = ++currentValue; +} + +function decrement(event) { + let input = event.target.nextSibling; + let currentValue = Math.floor(input.value); + + if (input.value > 0) { + input.value = --currentValue; + } +} + diff --git "a/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/generator.js" "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/generator.js" new file mode 100644 index 0000000..33c25e6 --- /dev/null +++ "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/generator.js" @@ -0,0 +1,56 @@ +generator = { + generateGoodsList() { + let list = document.createElement("table"); + document.body.appendChild(list); + + for (let row = 0; row <= config.rows; row++) { + let newRow = list.insertRow(row); + for (let col = 0; col < config.cols; col++) { + let newCell = newRow.insertCell(col); + + if (row === 0 && col >= 0) { + let head = ['Наименование', 'Цена', 'Количество', 'Сумма']; + for (let i = 0; i <= col; i++) { + newCell.innerHTML = head[i]; + newCell.className = 'bold'; + } + } else if (col === 0 && row > 0) { + let result = goods.map(a => a.name); + for (let i = 0; i < row; i++) { + newCell.innerHTML = result[i]; + } + } else if (row > 0 && col === 2) { + let buttonNeg = document.createElement('button'); + buttonNeg.type = 'button'; + buttonNeg.className = 'buttons'; + buttonNeg.innerText = ' - '; + newCell.appendChild(buttonNeg); + buttonNeg.addEventListener('click', decrement); + + let form = document.createElement("input"); + form.type = 'text'; + form.className = 'form'; + form.placeholder = '0'; + newCell.appendChild(form); + + let buttonPos = document.createElement('button'); + buttonPos.type = 'button'; + buttonPos.className = 'buttons'; + buttonPos.innerText = ' + '; + newCell.appendChild(buttonPos); + buttonPos.addEventListener('click', increment); + } else if (row > 0 && col === 1) { + let result = goods.map(a => a.price); + for (let i = 0; i < row; i++) { + newCell.className = 'price'; + newCell.innerHTML = result[i] + ' рублей.'; + } + } + } + } + }, + + //1. при нажатии на "+" в поле "количество" увеличивать число на 1, в поле "сумма" помещать сумму в рублях из расчета price * amount; + //2. при нажатии на "-" совершать противоположное действие; + // 3. Под таблице ввыводить строку описания состояния карзины. "В вашей карзине ...(помещать сумму всех значений 'количества') товаров на сумму ...(общая сумма из поля "сумма")"; +} diff --git "a/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/goods.js" "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/goods.js" new file mode 100644 index 0000000..3b5b5e6 --- /dev/null +++ "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/goods.js" @@ -0,0 +1,68 @@ +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/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/index.html" "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/index.html" new file mode 100644 index 0000000..4fc1aae --- /dev/null +++ "b/6 \321\203\321\200\320\276\320\272, \320\272\320\276\321\200\320\267\320\270\320\275\320\260/index.html" @@ -0,0 +1,17 @@ + + +
+ + + + +' + validateLogin(login.value).message + '
'); + } else { + if (loginErrorMessage) loginErrorMessage.remove(); + } + + if (!validatePassword(password.value).valid) { + if(!passwordErrorMessage) password.insertAdjacentHTML('afterEnd', '' + validatePassword(password.value).message + '
'); + } else { + if (passwordErrorMessage) passwordErrorMessage.remove(); + } + + if (!validatePasswordConf(passwordConf.value, password.value).valid) { + if(!passwordConfErrorMessage) passwordConf.insertAdjacentHTML('afterEnd', '' + validatePasswordConf(passwordConf.value).message + '
'); + } else { + if(passwordConfErrorMessage) passwordConfErrorMessage.remove(); + } + + if (validateLogin(login.value).valid && + validatePassword(password.value).valid && + validatePasswordConf(passwordConf.value, password.value).valid) alert('Форма отправлена!'); +}