Performing Mathematical Calculations
JavaScript Arithmetic Operators• Arithmetic operators are used to perform  mathematical calculations on variables and/or  ...
Arithmetic OperatorsOperator               Description   +                     Addition   -                   Subtraction ...
Web browser result: 10 + y= 22Explanation:var (means variable, optional) This are used to hold values and   expressions.le...
<script>msg1= “My Birthday is”msg2= “December 25, 1972”msg3= msg1 + msg2;alert(“ ”+msg3+””)</script>Web browser result:Exp...
If you add a numeric value and a text or string      value, the result will be a text or stringExamples:           Stateme...
• <script>• z="13"+"13";• x= 13+13;• document.write(""+z+"");• alert(""+x+"");• </script>• Result= 1313 (because values on...
• <script>• var z= parseFloat("13");• var x= 13• var y= z + x;• document.write(""+y+"");• </script>RESULT= z + x = 26• The...
COMPUQUIZ/EXERCISES1. A symbol or other character indicating an  operation that acts on one or more elements.2. This are u...
Performing calculations using java script
Upcoming SlideShare
Loading in …5
×

Performing calculations using java script

464 views

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
464
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Performing calculations using java script

  1. 1. Performing Mathematical Calculations
  2. 2. 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:
  3. 3. Arithmetic OperatorsOperator Description + Addition - Subtraction * Multiplication / Division % Modulus (remainder of a division) ++ Increment -- Decrement
  4. 4. 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
  5. 5. <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.
  6. 6. 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
  7. 7. • <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)
  8. 8. • <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.
  9. 9. 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

×