Skip to content

Instantly share code, notes, and snippets.

@minhajuddin
Created September 1, 2016 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minhajuddin/bcad1330cc9dd84823ef4cf739e684d9 to your computer and use it in GitHub Desktop.
Save minhajuddin/bcad1330cc9dd84823ef4cf739e684d9 to your computer and use it in GitHub Desktop.
Simple Calculator
<!doctype html>
<div id='output'>Output: </div>
<input type="text" id="op1" placeholder="Input 1" />
<br>
<input type="text" id="op2" placeholder="Input 2" />
<br>
<button onclick="calculate()">Add</button>
<script>
// outputdiv, red, yellow
function blink(el, first, second){
el.style['background-color'] = first;
setTimeout(function(){
// outputdiv, yellow, red
blink(el, second, first);
},300)
}
function calculate(){
// get the data from the input boxes
var op1 = document.getElementById("op1").value,
op2 = document.getElementById("op2").value,
outputDiv = document.getElementById("output");
// we add
var sum = parseInt(op1) + parseInt(op2);
// we show it in the output
outputDiv.innerHTML = sum;
blink(outputDiv, 'red', 'yellow')
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment