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
1 change: 1 addition & 0 deletions hw5-1code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
renderer.render();
14 changes: 14 additions & 0 deletions hw5-1main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!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">
<link rel="stylesheet" href="hw5-1style.css">
<title>Document</title>
</head>
<body>
<script src="hw5-1renderer.js"></script>
<script src="hw5-1code.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions hw5-1renderer.js
Original file line number Diff line number Diff line change
@@ -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 += '<tr class="with_letters">';
for (let j = 0; j < letters.length; j++) {
board += '<td>'+ letters[j] + '</td>';
}
board += '</tr>';
}

for(let y = 0; y < numbers.length; y++) {
board += '<tr>';
for(let x = 0; x < numbers.length; x++) {

board += '<td></td>';
}

board += '<td class="with_numbers">' + numbers[y] + '</td>' + '</tr>';

}

return '<table><tbody>' + board + '</tbody></table>';
},
}
36 changes: 36 additions & 0 deletions hw5-1style.css
Original file line number Diff line number Diff line change
@@ -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;
}

26 changes: 26 additions & 0 deletions hw5-2basket.js
Original file line number Diff line number Diff line change
@@ -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 += '<li> ' + JSON.stringify(basket.goodlist[i].name) + '\n' + JSON.stringify(basket.goodlist[i].price) + ' рублей. ' + '\n' + JSON.stringify(basket.goodlist[i].amount) + ' шт.' + ' </li>';
}
list += '<hr><br> Всего в вашей карзине ' + basket.countTotalNumber() + ' товара. На сумму: ' + basket.countTotalPrice() + ' рублей.';
return '<ul>' + list + '</ul>';
},
}



20 changes: 20 additions & 0 deletions hw5-2box.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions hw5-2code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
basketGeneration.generate();
69 changes: 69 additions & 0 deletions hw5-2goods.js
Original file line number Diff line number Diff line change
@@ -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();
}
});

19 changes: 19 additions & 0 deletions hw5-2main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!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">
<link rel="stylesheet" href="hw5-2style.css">
<title>Document</title>
</head>

<body>
<script src="hw5-2box.js"></script>
<script src="hw5-2goods.js"></script>
<script src="hw5-2basket.js"></script>
<script src="hw5-2code.js"></script>
</body>

</html>
3 changes: 3 additions & 0 deletions hw5-2style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
html {
background: darkseagreen;
}