Skip to content

Instantly share code, notes, and snippets.

@jl91
Created March 31, 2017 02:16
Show Gist options
  • Save jl91/5e6ee9663d1244114e020960ccee3b66 to your computer and use it in GitHub Desktop.
Save jl91/5e6ee9663d1244114e020960ccee3b66 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
</head>
<body>
<input type="text" readonly="readonly" name="numbers">
<button id="plus" onclick="plus()">+</button>
<button id="minus" onclick="minus()">-</button>
<script>
var counter = 0;
var numbers = document.getElementsByName('numbers')[0];
numbers.value = counter;
function plus() {
numbers.value = (parseFloat(numbers.value) + 0.5);
}
function minus() {
var minimumValue = 0;
var currentValue = parseFloat(numbers.value) - 0.5;
if (currentValue < minimumValue) {
currentValue = minimumValue;
}
numbers.value = currentValue;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment