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 :




5 1 vote
Article Rating
Subscribe
Notify of
guest

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

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Suryakumar Pandey

Similar kind of question is in Btech CSC (web technologies) thanks posting such a post

Sanjay Prasad

Thanks Suryakumar, we are going more Btech Computer Science solutions soon