Created
September 1, 2016 10:06
-
-
Save minhajuddin/bcad1330cc9dd84823ef4cf739e684d9 to your computer and use it in GitHub Desktop.
Simple Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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