Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions cannot do the additional operator

Have Programming Question? Ask it here!
 
 
 


siti umairah
cannot do the additional operator
2 Answer(s)      a year and 11 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>

Advertisement
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...



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    
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
What is the % operator?
What is the % operator?   Hi, What is the % operator? thanks
Java operator
Java operator  What are the legal operands of the instanceof operator
Java operator
Java operator  What is the difference between the prefix and postfix forms of the ++ operator
Java operator
Java operator  Which Java operator is right associative
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
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
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
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
Cannot find tag library descriptor
Cannot find tag library descriptor  Cannot find tag library descriptor...? How to resolve in struts in eclipse
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>
java.lang.IllegalArgumentException: node to traverse cannot be null!
java.lang.IllegalArgumentException: node to traverse cannot be null!  Can Any body help me out regarding the above exception in Hibernate HQL
Java Questionmark operator
;  The only ternary (i.e. takes three values) operator in Java is the conditional operator.  Syntax: boolean-expression... This operator returns one of two values depending on a third value
cannot find symbol - Java Beginners
cannot find symbol  public class Areatest { public static void main(String[]args) { Figure[]figures={new Triangle(2.0,3.0,3.0),new Rectangle(4.0,6.0),new Square(5.0)}; for(int i=0;i
SQL BETWEEN Operator
SQL BETWEEN Operator       The SQL Between Operator works where you want to select a range of data between two values. In SQL, the BETWEEN operator is used to select a range
java.lang.IllegalArgumentException: node to traverse cannot be null!
java.lang.IllegalArgumentException: node to traverse cannot be null!  Hi, I am new to Hibernate. I am facing the problem java.lang.IllegalArgumentException: node to traverse cannot be null! while updating a row. The code
Explain the ternary conditional operator in PHP?
Explain the ternary conditional operator in PHP?  Explain the ternary conditional operator in PHP
ls: cannot access >: No such file or directory
ls: cannot access >: No such file or directory  import java.io.BufferedReader; import java.io.InputStreamReader; public class Example...: cannot access >: No such file or directory error is displayed .No f.txt
javascript equality operator
javascript equality operator  javascript equality operator - What are the different ways to check the equality between strings?   javascript equality operator Equal (==) Not equal (!=) Strict equal
php do while break
php do while break   receiving a Fatal saying cannot break/continue.. please suggest. Thank U
org.apache.struts.action.ActionMessage cannot be cast to org.apache.struts.action.ActionError - Struts
org.apache.struts.action.ActionMessage cannot be cast...: org.apache.struts.action.ActionMessage cannot be cast to org.apache.struts.action.ActionError... java.lang.ClassCastException: org.apache.struts.action.ActionMessage cannot
JSP cannot find symbol error - JSP-Servlet
JSP cannot find symbol error  Suppose-- we created 'a.jsp' in which we make a database connection... how to retrieve 'new' here... If I want to access the 'new' string within the form what should i do???  
java.lang.IllegalArgumentException: node to traverse cannot be null!
java.lang.IllegalArgumentException: node to traverse cannot be null!  In my Hibernate program following error is coming: java.lang.IllegalArgumentException: node to traverse cannot be null
JSP cannot log to FileAppender - Log4J
JSP cannot log to FileAppender  Hi, Thank you for your attention :) I have a webapp running on Tomcat 5.5, which does all its logging using Log4j. At the moment, it logs fine to console when run from class main method
null pointer exception cannot be removed
null pointer exception cannot be removed  class list { public...=0; public int q=0; public static int i=0; public arraylist() { int...(int p,int q){ int y=0; for (y=0;y } else arraylist.abcd[p
image cannot be saved - Java Beginners
image cannot be saved  In the following program when we click on the menu item import, we can show any image on the panel but when we click on save the image is not drawn on the desired location.......please check the following
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
Java error cannot find symbol
Java error cannot find symbol In this section you will learn about "cannot find symbol" in java. Java cannot find symbol is a type of error occurs... the variable in use its trying to refer, then it will give a error cannot find symbol
Simple Assignment Operator
Simple Assignment Operator       Assignment operator is the most common operator almost used with all programming languages
Java "&" operator
Java "&" operator. In this section you will learn how to use "&" operator in java. Java provide six types of operators: among them one is Bitwise operator which can be applied to integer, long,  int
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
do the following
do the following  write a program to enter the string and do the following 1- count totle number of vowel 2- replace vowel 3- delete the charactor from given value 4- riverce the string 5- convert second word in upercase 6
Advertisements
 

 

 

DMCA.com