Skip to content

Instantly share code, notes, and snippets.

@jl91
Created March 31, 2017 02:20
Show Gist options
  • Save jl91/a667833bb89c09d38dd233fba6c7cde3 to your computer and use it in GitHub Desktop.
Save jl91/a667833bb89c09d38dd233fba6c7cde3 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;
var minimumValue = 0;
var maximumValue = 10;
function plus() {
var currentValue = parseFloat(numbers.value) + 0.5;
if (currentValue > maximumValue) {
currentValue = maximumValue;
}
numbers.value = currentValue;
}
function minus() {
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