Simple Javascript Reckoner Code - Javascript Arithmetic
Write HTML Code For Simple JavaScript Calculator
Yesterday I revised the concept of HTML Forms as well as JavaScript. While revising I encountered a University enquiry stating, "Q. Write Influenza A virus subtype H5N1 HTML Code To Make Simple Calculator Using Javascript Functions as well as HTML Forms. Calculator Must Take Any Two Numbers from User as well as Perform five Basic Arithmetic Operations i.e Addition, Subtraction, Multiplication, Division as well as Modulo".
I gave it a endeavor to write this pocket-size reckoner application (using Javascript as well as HTML Forms) as well as managed to ambit next working script. This Javascript application is really simple, necessarily commented as well as is slow to understand. I promise it may examine useful to those interested inwards learning javascript functions, so experience similar sharing. To empathise 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 tell 'Number 1' as well as 'Number 2'. --> <!-- 2. Perform Addition, Subtraction, Multiplication, Division as well as Modulus. --> <!-- 3. Result must live on displayed on same HTML Page when respective push is clicked. --> <!-- 4. Use <input> tag (HTML Forms Concept) amongst onclick.--> <!-- 5. Call private Javascript Function, position them within <head> tag only.--> <!-- 6. Javascript Tutorial/Code For Computer Science Students. --> <!-- 7. Tested as well as 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 motility into 1st number. --> Number 1: <input type="text" name="number1"> <br> <!-- Here user volition motility into 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 when clicked, calls exclusively 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 as well as glue inwards a higher house HTML Code inwards a notepad as well as relieve it every bit JavaScript-Calculator.html. Now opened upward this saved HTML file inwards whatsoever spider web browser (e.g: Internet Explorer amongst ActiveX Enabled) to acquire effect something similar this...
"Thanks! For reading my JavaScript Tutorial. Enjoy Scripting"...Gaurav Akrani.
No comments