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
28 changes: 28 additions & 0 deletions 5/cart/cart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<section>
<div>
<img src="img/avocado.png" alt="">
<p>avocado</p>
<button class="button plus" data-id="avocado">+</button>
<button class="button minus" data-id="avocado">-</button>
</div>
<div>
<img src="img/carrot.jpg" alt="">
<p>carrot</p>
<button class="button plus" data-id="carrot">+</button>
<button class="button minus" data-id="carrot">-</button>
</div>
<div>
<img src="img/basket.png" alt="" class="basket">
</div>
</section>
<script src="cart.js"></script>

</body>
</html>
60 changes: 60 additions & 0 deletions 5/cart/cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
let items = {
'carrot': 25,
'avocado': 100
};

let cart = {
'carrot': 0,
'avocado': 0
};

document.onclick = event => {
if (event.target.classList.contains("plus")){
plusFunc(event.target.dataset.id);
};
if (event.target.classList.contains("minus")){
minusFunc(event.target.dataset.id);

};
if (event.target.classList.contains("basket")){
basketAlert();
};
};
// plus
const plusFunc = (id) => {
cart[id]++;
renderCart();
};

//minus
const minusFunc = (id) => {
if(cart[id] - 1 == 0){
deleteFunc(id);
"button".opacity = 0;

return true
};
cart[id]--;
renderCart();
};

const renderCart = () => {
console.log(cart)
};

//delete
const deleteFunc = id => {
delete cart[id];
renderCart();
};


const basketAlert = () => {
var price = 0
for(var i in cart){
price = price + (cart[i] * items[i])
};
console.log(price);
};

renderCart();
Binary file added 5/cart/img/avocado.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5/cart/img/basket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5/cart/img/carrot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions 5/chess/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet" href="styles.css">
<body>
<div class="main-block"></div>
<script src="chess.js"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions 5/chess/chess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function chess(){
let mainBlock = document.querySelector('.main-block');
let block;
let flag = true;
for (let i = 0; i<8; i++){
for(let j = 0; j<8; j++){
if (j == 0) flag = !flag
block = document.createElement('div');
if (flag) block.className = 'block black';
else block.className = 'block white';
mainBlock.appendChild(block);
flag = !flag;
}
}
}

chess();
17 changes: 17 additions & 0 deletions 5/chess/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.main-block {
width: 560px;
height: 560px;
margin: 30px auto;
border: 1px solid black;
}
.block {
width: 70px;
height: 70px;
float:left;
}
.black {
background:black;
}
.white {
background: whitesmoke;
}