Last active
March 5, 2018 16:31
-
-
Save KristofferK/47be267c84c4494f03da8a18967d31eb to your computer and use it in GitHub Desktop.
Example for friend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Frugt</title> | |
<meta charset="utf-8"/> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-4"> | |
<img src="https://image.flaticon.com/icons/png/128/686/686452.png"/> | |
<button id="buy-pineapple" class="btn btn-info">Køb ananas</button> | |
</div> | |
<div class="col-md-4"> | |
<img src="https://image.flaticon.com/icons/png/128/686/686448.png"/> | |
<button id="buy-banana" class="btn btn-info">Køb banan</button> | |
</div> | |
<div class="col-md-4"> | |
<img src="https://image.flaticon.com/icons/png/128/686/686442.png"/> | |
<button id="buy-orange" class="btn btn-info">Køb appelsin</button> | |
</div> | |
</div> | |
<hr/> | |
<div class="row"> | |
<div class="col-md-6"> | |
Ananas købt: <span id="count-pineapple"></span><br/> | |
Bananer købt: <span id="count-banana"></span><br/> | |
Appelsiner købt: <span id="count-orange"></span><br/><br/> | |
Pris i alt: <span id="total-price"></span> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> | |
<script> | |
const updateCart = () => { | |
document.getElementById('count-pineapple').innerText = fruitsBought.pineapple; | |
document.getElementById('count-banana').innerText = fruitsBought.banana; | |
document.getElementById('count-orange').innerText = fruitsBought.orange; | |
const fruitCount = fruitsBought.pineapple + fruitsBought.banana + fruitsBought.orange; | |
document.getElementById('total-price').innerText = fruitCount * 4 + ' kr.'; | |
}; | |
let fruitsBought = {pineapple: 0, banana: 0, orange: 0}; | |
document.getElementById('buy-pineapple').onclick = e => { | |
fruitsBought.pineapple++; | |
updateCart(); | |
} | |
document.getElementById('buy-banana').onclick = e => { | |
fruitsBought.banana++; | |
updateCart(); | |
} | |
document.getElementById('buy-orange').onclick = e => { | |
fruitsBought.orange++; | |
updateCart(); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment