Skip to content

Instantly share code, notes, and snippets.

@JHarry444
Created June 16, 2020 08:57
Show Gist options
  • Save JHarry444/2e6a3ea3c632a886f4ce09800503589d to your computer and use it in GitHub Desktop.
Save JHarry444/2e6a3ea3c632a886f4ce09800503589d to your computer and use it in GitHub Desktop.
<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>
(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