• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
CSIS 138 JavaScript Class2
 

CSIS 138 JavaScript Class2

on

  • 1,005 views

Instructor Teresa Pelkie at Palomar College - Variables, Calculations, "if" statement

Instructor Teresa Pelkie at Palomar College - Variables, Calculations, "if" statement

Statistics

Views

Total Views
1,005
Views on SlideShare
1,004
Embed Views
1

Actions

Likes
0
Downloads
31
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • The JavaScript Language consists of objects CSIS 138 Instructor Teresa Pelkie Class 2 - Summer 2008

CSIS 138 JavaScript Class2 CSIS 138 JavaScript Class2 Presentation Transcript

  • JavaScript – Class 2
      • prompt()
      • operators
      • Calculations
      • if statement
    • prompt("Please enter your name", "");
    • <head>
    • <script language=&quot;JavaScript&quot;>
    • var myPrompt ;
    • myPrompt = prompt(&quot;Please enter your name&quot;, &quot;&quot;);
    • </script>
    • </head>
    • <body>
    • <script language=&quot;JavaScript&quot;>
    • document.write( myPromp t);
    • </script>
    • </body>
    • Mathematical operators : + - / * % •
    • Precedence - * and / are performed first
    • unless you use parenthesis
    • Assignment operator: = also assigns a value
    • to a variable
    • Increment and decrement operators: ++ --
    • Comparison operators: < <= > >= == !=
    • Logical operators: && || !
    • Commonly used with an “if” statement
    • <script language=&quot;JavaScript&quot;>
    • alert(1 + 1);
    • </script>
    • <script language=&quot;JavaScript&quot;>
    • var firstNumber = 40;
    • var secondNumber = 20;
    • alert(firstNumber + secondNumber);
    • </script>
    • NaN – Not a Number
    • a special value in JavaScript that is returned if
    • you do a calculation with a non-number character
    • IsNaN() – function
    • tests if a variable is a number or not
    • – returns a Boolean data type
    • returns true if it is a string (because a string is not a number)
    • returns false if it is a number
    • <script language=&quot;JavaScript&quot;>
    • alert(isNaN(&quot;teresa&quot;));
    • </script>
    See page 6 in handout
    • if statement
    • <script language=“JavaScript”>
    • var variable1 = 123;
    • var variable2 = 123;
    • if ( variable1 == variable2 )
    • {
    • alert (&quot;condition true&quot;);
    • }
    • </script>
    no semicolon == means: is the same or is equal or is true the condition to be evaluated is inside the parenthesis code to be executed if the condition is true see page 7 handout
    • Using comparison and logical operators
    • <script language=“JavaScript”>
    • var variable1 = 2;
    • var variable2 = 4;
    • var variable3 = 6;
    • if ( ( variable1 < variable2 ) || ( variable2 < variable3 ) )
    • {
    • alert (&quot;condition true&quot;);
    • }
    • </script>
    See page 8 and 9 in handout
    • if else statement
    see page 10 handout Gives you the ability to execute code when the condition evaluates to true and also when it evaluates to false if (condition) { code here will execute if condition is true’ } else { code here will execute if condition is false; }
    • if else statement
    see page 10 handout <script language=“JavaScript”> var variable1 = 123; var variable2 = 124; if (variable1 == variable2) { alert (&quot;true&quot;); } else { alert(&quot;false&quot;); } </script>
    • if else if statement
    see page 11 handout var variable1 = 123; var variable2 = 124; if (variable1 == variable2) { alert(&quot;equal&quot;); } else if (variable1 < variable2) { alert(&quot;less than&quot;); } else { alert(&quot;none of the above&quot;); } “ else if “block can be repeated as needed
    • JavaScript – Class 2
    • Assignment 2