Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

Pure JavaScript Simple Calculator Tutorial

Pure JavaScript Simple Calculator Tutorial

In this tutorial we are going to learn pure  JavaScript simple Calculator Application through input text box, complete code is given below and code is easy to understand, still, if you find any kind of difficulty then please comment, I will try to clear you …

JavaScript Simple Calculator Complete Code :


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript Calculator</title>
</head>
<body>
<input type="text" id="num1" placeholder="Enter Number">
<input type="text" id="num2" placeholder="Enter Number">
<select id="sel">
<option value="">Select</option>
<option value="division">division</option>
<option value="substract">substract</option>
<option value="addition">addition</option>
<option value="multiply">multiply</option>
</select>
<input type="submit" onclick="addition()" value="submit">
<br/>
<div id="result"></div>
<script>
function addition(){
var num1= parseFloat(document.getElementById("num1").value);
var num2= parseFloat(document.getElementById("num2").value);
var sel=document.getElementById("sel").value;
var result;
if(sel=='addition'){
result=num1+num2;
}else if(sel=='substract'){
result=num1-num2;
}else if(sel=='division'){
result=num1/num2;
}else{
result=num1*num2;
}
document.getElementById("result").innerHTML=result;
}
</script>
</body>
</html>

JavaScript Simple Calculator Demo :




 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do you have any Query / Suggestion