Standard math operators: +, -, *, / work with numbers
y = 3.5*x + 4;
a = (b - c)*d/4
x = x + 1
The + operator can also be used to add (concatenate) strings
Due to order of precedance use parentheses for complicated expressions
Modulus operator % returns the remainder
x = 5%3 //x will equal 2
Used to increment or decrement variables
x++ and ++x are the same as x = x + 1
x-- and --x are the same as x = x - 1
x+=3 is the same as x = x + 3
<html> <head><script> var x = 10; var y = 3; var z = 0 var s = "" z = x/y; alert("z = " + z) x = x%y; alert("x = " + x) x++; alert("x after x++ = " + x) x = x - 1; alert("x-1 is " + x) var a = 3+6/2-3%1; alert("a = " + a) alert(6.02E23*10E-23) </script> </head> <body> </body> </html>
Test the operators on strings (for example... alert("f"*"g"))
Create a page with two textboxes and a button. Create a function that is called on the "onclick" event of the button. Add code to the function so that:
The contents of the textboxes are added together and displayed in an alert.
One textbox is subtracted from the other and the result displayed in an alert.
The textboxes are multiplied and the result is displayed in an alert.
The remainder of the two textboxes is displayed in an alert.
Write code that keeps track of the number of times that a user clicks on a page.