Created
May 13, 2019 17:17
-
-
Save avishai84/554c9bdab84193e9cb1130a587c36390 to your computer and use it in GitHub Desktop.
Assignement.html
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 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> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code was based on the video below by Juriy Bura:
You Tube:
https://www.youtube.com/watch?v=nX0ajFKB2E0&t=1101s
Git:
https://gist.github.com/Juriy/c86710494a64271a4f38f6d9aca9c5a1