Your SlideShare is downloading. ×
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

CSIS 138 JavaScript Class2

759

Published on

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

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

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
759
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
34
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • The JavaScript Language consists of objects CSIS 138 Instructor Teresa Pelkie Class 2 - Summer 2008
  • Transcript

    • 1. JavaScript – Class 2
        • prompt()
        • operators
        • Calculations
        • if statement
    • 2.
      • prompt("Please enter your name", "");
    • 3.
      • <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>
    • 4.
      • Mathematical operators : + - / * % •
      • Precedence - * and / are performed first
      • unless you use parenthesis
      • Assignment operator: = also assigns a value
      • to a variable
      • Increment and decrement operators: ++ --
    • 5.
      • Comparison operators: < <= > >= == !=
      • Logical operators: && || !
      • Commonly used with an “if” statement
    • 6.
      • <script language=&quot;JavaScript&quot;>
      • alert(1 + 1);
      • </script>
      • <script language=&quot;JavaScript&quot;>
      • var firstNumber = 40;
      • var secondNumber = 20;
      • alert(firstNumber + secondNumber);
      • </script>
    • 7.
      • 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
    • 8.
      • <script language=&quot;JavaScript&quot;>
      • alert(isNaN(&quot;teresa&quot;));
      • </script>
      See page 6 in handout
    • 9.
      • 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
    • 10.
      • 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
    • 11.
      • 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; }
    • 12.
      • 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>
    • 13.
      • 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
    • 14.
      • JavaScript – Class 2
      • Assignment 2

    ×