Created
June 16, 2020 08:57
-
-
Save JHarry444/2e6a3ea3c632a886f4ce09800503589d to your computer and use it in GitHub Desktop.
This file contains 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
<html> | |
<head></head> | |
<body> | |
<input id="counter" value="0" type="number" /> | |
<button id="plus5">+5</button> | |
<button id="plus1" onclick="increment();">+</button><button id="minus1" onclick="decrement();">-</button> | |
<button id="minus5">-5</button> | |
<p id="myP">flfkdjhgdghdjgdfgndfkjg</p> | |
<script src="./js/counter.js"></script> | |
</body> | |
</html> |
This file contains 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
(function () { | |
function changeCounter(myEle) { | |
const counter = document.getElementById('counter'); | |
counter.value = parseInt(counter.value) + parseInt(myEle.innerText); | |
} | |
const plus5Button = document.getElementById('plus5'); | |
plus5Button.addEventListener('click', function () { | |
changeCounter(this); // this -> the element that has been clicked | |
}); | |
const minus5Button = document.getElementById('minus5'); | |
minus5Button.addEventListener('click', function () { | |
changeCounter(this); | |
}); | |
})(); | |
function increment() { | |
const counter = document.getElementById('counter'); | |
counter.value++; | |
} | |
function decrement() { | |
const counter = document.getElementById('counter'); | |
counter.value--; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment