Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save avishai84/554c9bdab84193e9cb1130a587c36390 to your computer and use it in GitHub Desktop.

Select an option

Save avishai84/554c9bdab84193e9cb1130a587c36390 to your computer and use it in GitHub Desktop.
Assignement.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<title>Counter</title>
<style>
body{
background:grey;
color:white;
font-size:20px;
}
p{
background-color:black;
display:inline-block;
padding:0 0 0 5px;
}
#counter{
color:Red;
background-color:yellow;
padding:1px 4px;
border-radius:4px;
}
button{font-size:18px;}
button:hover{cursor:pointer;}
</style>
</head>
<body>
<button value="add">+</button><button value="sub">-</button><button value="reset">reset</button><button value="random">random</button>
<p>Counter: <span id="counter">0</span></p>
</body>
<script>
const counter = document.getElementById('counter');
const add = {
count : function(){
var currCount = parseInt(counter.innerText);
currCount = currCount + 1;
return counter.innerHTML = currCount;
}
};
const sub = {
count : function(){
var currCount = parseInt(counter.innerText);
currCount = currCount - 1;
return counter.innerHTML = currCount;
}
};
const reset = {
count : function(){
return counter.innerHTML = 0;
}
};
const random = {
count : function(){
var currCount = Math.floor(Math.random() * 100);
return counter.innerHTML = currCount;
}
}
document.addEventListener('click', function(e){
switch(e.target.value){
case 'add':
add.count();
break;
case 'sub':
sub.count();
break;
case 'reset':
reset.count();
break;
case 'random':
random.count();
break;
}
},false);
</script>
</html>
@avishai84
Copy link
Author

avishai84 commented May 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment