Click here to load reader

Basic Programming by Mo Zhang. Notepad Notepad++ Dreamweaver Eclipse,

  • View
    238

  • Download
    2

Embed Size (px)

Text of Basic Programming by Mo Zhang. Notepad Notepad++ Dreamweaver Eclipse,

  • Slide 1

Basic Programming by Mo Zhang Slide 2 Notepad Notepad++ Dreamweaver Eclipse, Slide 3 Attribute Slide 4 Display Strings in JS document.write(Hello World); Slide 5 Comments int A = 3; int B = 11; int C; C = A + B; // the sum of two numbers. Slide 6 Comments Cont Multi-line comment /* Calculate the yaw Calculate the roll Calculate the pitch */ Slide 7 Variables Declaration of variables. var x = 3; Note: 1.Start the name with a letter or underscore. 2.The rest of characters have to be letters, underscores, or numbers. (Cannot use %, $, *,, &, etc.); 3.Variable names are case sensitive. Slide 8 Different Types of Variables Data typeExampleDeclaration integers0, 1, -3, 11, 13, 24, -103int Decimal numbers3.1415926Double, float Strings (text)HelloString BooleanTRUE/FALSE, 1/0Boolean, Bool Characters0, 1, c, %char Slide 9 Math Operators OperatorDescriptionExampleResult of xResult of y +Additionx=y+275 -Subtractionx=y-235 *Multiplicationx=y*2105 /Divisionx=y/22.55 % Modulus (division remainder) x=y%215 ++Incrementx=++y66 x=y++56 --Decrementx=--y44 x=y--54 X = ? and y = 5; Slide 10 Assignment Operators OperatorExampleSame AsResult =x=y x=5 +=x+=yx=x+yx=15 -=x-=yx=x-yx=5 *=x*=yx=x*yx=50 /=x/=yx=x/yx=2 %=x%=yx=x%yx=0 Slide 11 If Statement Letting your computer make a decision if (condition) { } Slide 12 If Else Statement Letting your computer make a decision if (condition) { Event A; } else { Event B; } Slide 13 If...else if...else Statement Syntax if (condition1) { code to be executed if condition1 is true } else if (condition2) { code to be executed if condition2 is true } else { code to be executed if neither condition1 nor condition2 is true } Slide 14 Comparison Operators Comparison operators are used in logical statements to determine equality or difference between variables or values. Given that x=5, the table below explains the comparison operators: Slide 15greater thanx>8false < less thanx= greater than or equal tox>=8false