Write HTML Code For Simple JavaScript Calculator
Yesterday I revised the concept of HTML Forms together with JavaScript. While revising I encountered a University interrogation stating, "Q. Write Influenza A virus subtype H5N1 HTML Code To Make Simple Calculator Using Javascript Functions together with HTML Forms. Calculator Must Take Any Two Numbers from User together with Perform five Basic Arithmetic Operations i.e Addition, Subtraction, Multiplication, Division together with Modulo".
I gave it a endeavour to write this pocket-sized figurer application (using Javascript together with HTML Forms) together with managed to create next working script. This Javascript application is really simple, necessarily commented together with is tardily to understand. I promise it may test useful to those interested inwards learning javascript functions, thence experience similar sharing. To sympathise more, How Javascript Works? I recommend you lot refer this JavaScript Tutorial.
JavaScript Code - Simple JavaScript Calculator
<html> <head> <title>Simple Javascript Calculator - Basic Arithmetic Operations</title> <!-- Aim: Write HTML Code Using JavaScript Functions To Perform Basic Arithmetic Operations. --> <!-- 1. Take Two numbers from user nation 'Number 1' together with 'Number 2'. --> <!-- 2. Perform Addition, Subtraction, Multiplication, Division together with Modulus. --> <!-- 3. Result must live on displayed on same HTML Page when respective push clit is clicked. --> <!-- 4. Use <input> tag (HTML Forms Concept) alongside onclick.--> <!-- 5. Call private Javascript Function, position them within <head> tag only.--> <!-- 6. Javascript Tutorial/Code For Computer Science Students. --> <!-- 7. Tested together with Written By (c) Gaurav Akrani. --> <script language="javascript" type="text/javascript"> component subdivision multiply(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a*b; document.calculator.total.value=c; } </script> <script language="javascript" type="text/javascript"> component subdivision addition(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a+b; document.calculator.total.value=c; } </script> <script language="javascript" type="text/javascript"> component subdivision subtraction(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a-b; document.calculator.total.value=c; } </script> <script language="javascript" type="text/javascript"> component subdivision division(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a/b; document.calculator.total.value=c; } </script> <script language="javascript" type="text/javascript"> component subdivision modulus(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a%b; document.calculator.total.value=c; } </script> </head> <body> <!-- Opening a HTML Form. --> <form name="calculator"> <!-- Here user volition acquire inwards 1st number. --> Number 1: <input type="text" name="number1"> <br> <!-- Here user volition acquire inwards 2d number. --> Number 2: <input type="text" name="number2"> <br> <!-- Here effect volition live on displayed. --> Get Result: <input type="text" name="total"> <br> <!-- Here respective push clit when clicked, calls alone respective artimetic function. --> <input type="button" value="ADD" onclick="javascript:addition();"> <input type="button" value="SUB" onclick="javascript:subtraction();"> <input type="button" value="MUL" onclick="javascript:multiply();"> <input type="button" value="DIV" onclick="javascript:division();"> <input type="button" value="MOD" onclick="javascript:modulus();"> </form> </body> </html>
Download JavaScript Calculator HTML Code Here : JavaScript Calculator!
JavaScript Output - Perform Arithmetic Operations
Copy together with glue higher upwardly HTML Code inwards a notepad together with salve it every bit JavaScript-Calculator.html. Now opened upwardly this saved HTML file inwards whatsoever spider web browser (e.g: Internet Explorer alongside ActiveX Enabled) to acquire effect something similar this...
"Thanks! For reading my JavaScript Tutorial. Enjoy Scripting"...Gaurav Akrani.