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



Home Answers Viewqa JavaScriptQuestions cannot do the additional operator
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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

 

 

DMCA.com