Like this presentation? Why not share!

# Performing calculations using java script

## on Jan 08, 2013

• 649 views

### Views

Total Views
649
Views on SlideShare
649
Embed Views
0

Likes
0
Downloads
3
Comments
0

No embeds

### Upload Details

Uploaded via as Microsoft PowerPoint

### Usage Rights

© All Rights Reserved

### Report content

• Comment goes here.
Are you sure you want to
Your message goes here
Edit your comment

## Performing calculations using java scriptPresentation Transcript

• Performing Mathematical Calculations
• JavaScript Arithmetic Operators• Arithmetic operators are used to perform mathematical calculations on variables and/or values. These operators are combined with values and/or variables to form a JavaScript expression.• A symbol or other character indicating an operation that acts on one or more elements.• The different JavaScript arithmetic operators are listed as follows:
• Arithmetic OperatorsOperator Description + Addition - Subtraction * Multiplication / Division % Modulus (remainder of a division) ++ Increment -- Decrement
• Web browser result: 10 + y= 22Explanation:var (means variable, optional) This are used to hold values and expressions.let variable y = 12.Mathematical expression= let variable x= 10 + y (where y is equal to 12)document .write display the result: 10 + y= 22
• <script>msg1= “My Birthday is”msg2= “December 25, 1972”msg3= msg1 + msg2;alert(“ ”+msg3+””)</script>Web browser result:Explanation:The (+) operator add string variables or text values together.
• If you add a numeric value and a text or string value, the result will be a text or stringExamples: Statement Resultz= 10+5; 15z= “3”+ “3”; 33z= 8+ “15”; 815z= “11”+12; 1112
• • <script>• z="13"+"13";• x= 13+13;• document.write(""+z+"");• alert(""+x+"");• </script>• Result= 1313 (because values on z are considered as “text values”)• Result= 26(because values on x are numeric values)
• • <script>• var z= parseFloat("13");• var x= 13• var y= z + x;• document.write(""+y+"");• </script>RESULT= z + x = 26• The parseFloat() function parses a string and returns a floating point number.• This function determines if the first character in the specified string is a number. If it is, it parses the string until it reaches the end of the number, and returns the number as a number, not as a string.• Note: Only the first number in the string is returned!• Note: Leading and trailing spaces are allowed.• Note: If the first character cannot be converted to a number, parseFloat() returns NaN.
• COMPUQUIZ/EXERCISES1. A symbol or other character indicating an operation that acts on one or more elements.2. This are used to hold values and expressions.3. Write the code for the following:variable x = 33variable y= 10 + xPut the result in an alert box