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 :
Similar kind of question is in Btech CSC (web technologies) thanks posting such a post
Thanks Suryakumar, we are going more Btech Computer Science solutions soon