Skip to content

Instantly share code, notes, and snippets.

@sandhikagalih
Created February 3, 2021 14:39
Show Gist options
  • Save sandhikagalih/db7737d63c9081095b0dc71f2347a280 to your computer and use it in GitHub Desktop.
Save sandhikagalih/db7737d63c9081095b0dc71f2347a280 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" id="angka" value="1">
<button type="button" id="tambah">+</button>
<button type="button" id="kurang">-</button>
<script>
const angka = document.querySelector('#angka');
const tambah = document.querySelector('#tambah');
const kurang = document.querySelector('#kurang');
// tombol tambah diklik
tambah.addEventListener('click', function() {
angka.value++;
})
// tombol kurang diklik
kurang.addEventListener('click', function() {
angka.value--;
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment