cannot do the additional operator

Ads

 
 
 

Share on Google+Share on Google+

siti umairah
cannot do the additional operator
2 Answer(s)      4 years and 7 months ago
Posted in : JavaScript Questions

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>
Ads
View Answers

October 4, 2012 at 6:07 PM


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>


October 4, 2012 at 10:18 PM


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









Related Tutorials/Questions & Answers:
cannot do the additional operator
cannot do the additional operator  i got problem with additional and multiplication operator...please anyone help me <html> <head>... text field var operator = formCalculator.operator.value; //get input from first
What does the delete operator do?
What does the delete operator do?  What does the delete operator do
Advertisements
What does the delete operator do?
What does the delete operator do?  What does the delete operator do
Appendix A. Additional materials
 Appendix A. Additional materialsPrev Part II. Appendixes Next    Appendix A. Additional materialsSource code ibm-287.code.zip    
What is the % operator?
What is the % operator?   Hi, What is the % operator? thanks
AND operator in hibernate.
AND operator in hibernate.  How to use AND operator in hibernate
OR operator in hibernate.
OR operator in hibernate.  How to use OR operator in hibernate
Java operator
Java operator  Which Java operator is right associative
Java operator
Java operator  What is the difference between the prefix and postfix forms of the ++ operator
Java operator
Java operator  What are the legal operands of the instanceof operator
like operator
like operator  how to select exact value using like operator in php
ternary operator
ternary operator  (Ternary operator) Dearness Allowance= 25% of Basic pay house rent allowance= 15% of basic pay Provident fund= 8.33% of Basic pay Net pay=basic pay+Dearness allowance+house rent allowance Gross pay= Net pay
LIKE Operator
LIKE Operator       The LIKE operator is used for searching  a specified pattern in the column. In this example we will show you how to use the Like operator to get
What is the difference between the Boolean & operator and the && operator?
What is the difference between the Boolean & operator and the && operator?   Hello, What is the difference between the Boolean & operator and the && operator? thanks
SQL IN Operator
SQL IN Operator       SQL IN Operator helps you to specify multiple values in a WHERE Clause... IN Operator. In this example, we create a table 'Stu_Table'. The create
cannot connect to database - JDBC
cannot connect to database  Iam using eclipse in my system ,when connecting the database mysql version 5.0 to the eclipse iam getting an error as ""Creating connection to mysql has encountered a problem.Could not connect to mysql
cannot find symbol method nextchar()??
cannot find symbol method nextchar()??  import java.util.Scanner; public class Calc5{ public static void main(String args[]){ Scanner... operand1, operand2 and operator(+,-,x,/)"); int a = obj.nextInt
The import javax.validation cannot be resolved
The import javax.validation cannot be resolved  Hi, I have a web application and due to missing maven dependency it is giving following error in Eclipse: The import javax.validation cannot be resolved. What maven dependency
org.hibernate.validator cannot be resolved error
org.hibernate.validator cannot be resolved error  In Hibernate based application my application is giving following error: org.hibernate.validator cannot be resolved error Program is not compiling due to this error. How
cannot display an arrayList in JSP
cannot display an arrayList in JSP  Hello, My bean is called Zone, i got all Zones from sql Server with Hibernate. in DAO.Class: print("List zones = session.createQuery("FROM Zone").list();"); i want to send this List from
combobox cannot be resolved in JavaFX
combobox cannot be resolved in JavaFX  I want to design one application with a combobox containing items. and while selecting i want to give user autocomplete suggestion. but while doing this combobox is not getting resolved. i
c++ operator overloading
c++ operator overloading  What is operator overloading? and what is mean by overloading?? Can anyone please explain the concept in regards to C
Cannot find tag library descriptor
Cannot find tag library descriptor  Cannot find tag library descriptor...? How to resolve in struts in eclipse
System.out.println cannot be written inside a class
System.out.println cannot be written inside a class  why System.out.println cannot be written inside a class
PdfCopyFields cannot be resolved - Java Beginners
PdfCopyFields cannot be resolved   Trying to concatenate PDF files. I downloaded the example from PdfCopyFields cannot be resolved but other
PdfCopyFields cannot be resolved - Java Beginners
PdfCopyFields cannot be resolved  PdfCopyFields cannot be resolved but other classes in the iText-2.1.0.jar are resolved. Any suggestions? Thanks
PHP Array Operator
Array Operators: In PHP there are many operators are available which works on more than one array, to get union of two arrays, to check the identity, equality etc. '+' operator is used to get the union of two arrays
Java 'or' operator
Java 'or' operator       OR operator is a kind of a conditional operators, which... between the two boolean expressions. The OR operator (|) is similar
why we use ^ operator in sql, and what is the meaning of that operator?
why we use ^ operator in sql, and what is the meaning of that operator?  why we use ^ operator in sql, and what is the meaning of that operator
PHP Concatenation Operator
PHP Concatenation Operator  Hi friends, Can any one guide me how to use the concatenation string operator in PHP
Cannot assign an ArrayList to an empty ArrayList
Cannot assign an ArrayList to an empty ArrayList  I have a java file, in which a method returns an ArrayList. This ArrayList is supposed to contain...; } FoundStudents.jsp I want to do something like this: ArrayList<Student>
Tutorials   
Java Spring Hibernate Struts Training code for programming How can I dynamically load user-entered data as content of jquery dialog? java webcam integration question java coding Fix Scrollbar position in a checkboxList after postback Information Save Alert Country wise redirection to files Interface in javascript connect database with javascript Zip Code ZipCode how to validate the email login How to play FLV video files on Ipad using HTML code or javascript code? Nitobi Grid is not working in IE10/IE11 jquery issue plese help RegEx Tree structure from json whose parents can be dragged and dropped from child newyorklife insurance getElementById not working javascript code for search in html file Implement The Skeleton Code Implement This Skeleton Code Mobile Automation using Appium Computer forensic application Java: Searching a string from doc files java linked list urgent !!! java linked list urgent!!! library management library management library management library management question Html form using JavaScript to display the table content java how to prevent no from unroundin off on clicking text box again in JSP and Jquery graph generation from xml design file display data from database in textbox when id entered in textbox Javascript Code for all fields how to get HTTP GET request value using javascript array Javascript Querry autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me Create SpreadSheet same as excel using java applet Create SpreadSheet same as excel using java applet How to change focus among multiple select boxes? Write JQUERY Code Write JQUERY Code Converting jsp variable to java variable java

Ads

 
Advertisement null

Ads