i got problem with additional and multiplication operator...please anyone help me
<html> <head> <title>Simple Calculator</title> <script language = "JavaScript"> // calculate function function calculate () { //get input from first text field var numberFirst = formCalculator.num1.value; //get input from first text field var operator = formCalculator.operator.value; //get input from first text field var numberSecond = formCalculator.num2.value; var total; // variable declaration var output; // variable declaration // if else..if if (operator == "+" ) total = numberFirst + numberSecond; else if (operator == "-") total = numberFirst - numberSecond; else if (operator == " * ") total = numberFirst * numberSecond; else total = numberFirst / numberSecond; // output from pop up alert window output = alert ( numberFirst + " " + operator + " " + numberSecond + " = " + total); } </script> </head> <body> <p align="center" class="style1">Simple Calculator</p> <!-- HTML form--> <form name = "formCalculator"> <p align="center"> <!-- first text field --> <input type="text" name="num1"> <!-- selection math operator menu --> <select name="operator"> <option selected value="+" > + <option value= "-" > - <option value= "*" > * <option value= "/" > / </select> <!-- second text field --> <input type="text" name="num2"> </p> <p align="center"> <input type="reset" name="Reset" value="Cancel"> <!-- submit button call calculate function --> <input type="submit" name="Submit" value="Calculate" onClick= "calculate()"> </p> </form> </body> </html>
We have modified your simple calculator program.
<html> <head> <title>Simple Calculator</title> <script language = "JavaScript"> // calculate function function calculate () { //get input from first text field var numberFirst = formCalculator.num1.value; //get input from first text field var operator = formCalculator.operator.value; //get input from first text field var numberSecond = formCalculator.num2.value; var total; // variable declaration var output; // variable declaration // if else..if if (operator == "+" ) total = parseInt(numberFirst) + parseInt(numberSecond); else if (operator == "-") total = parseInt(numberFirst) - parseInt(numberSecond); else if (operator == " * ") total = parseInt(numberFirst) * parseInt(numberSecond); else total = parseInt(numberFirst) / parseInt(numberSecond); // output from pop up alert window output = alert ( numberFirst + " " + operator + " " + numberSecond + " = " + total); } </script> </head> <body> <p align="center" class="style1">Simple Calculator</p> <!-- HTML form--> <form name = "formCalculator"> <p align="center"> <!-- first text field --> <input type="text" name="num1"> <!-- selection math operator menu --> <select name="operator"> <option selected value="+" > + <option value= "-" > - <option value= "*" > * <option value= "/" > / </select> <!-- second text field --> <input type="text" name="num2"> </p> <p align="center"> <input type="reset" name="Reset" value="Cancel"> <!-- submit button call calculate function --> <input type="submit" name="Submit" value="Calculate" onClick= "calculate()"> </p> </form> </body> </html>
the additional operator already done but i still have problem with multiplication operator...when i times 1 by 2, it will get answer 0.5...
Ads