les 2 javascript w2

14
Javascript 2 IF-Else / Switch / PopUp / Functions Mediatechnologie Blok 8

Upload: mvanginkel

Post on 19-May-2015

395 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Les 2 javascript w2

Javascript 2IF-Else / Switch / PopUp / Functions

Mediatechnologie Blok 8

Page 2: Les 2 javascript w2

IF - Else• if statement - use this statement to execute some code only if a specified condition is true

• if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false

• if...else if....else statement - use this statement to select one of many blocks of code to be executed

if (time < 12) { document.write("Goede Morgen"); }else { document.write("Goede Middag"); }

Page 3: Les 2 javascript w2

IF - Else

Page 4: Les 2 javascript w2

IF - Else

Page 5: Les 2 javascript w2

Switchswitch(n){case 1: execute code block 1 break;case 2: execute code block 2 break;default: code to be executed if n is different from case 1 and 2}

Page 6: Les 2 javascript w2

Switch

Page 7: Les 2 javascript w2

Pop-Upalert(“tekst");Alert

Page 8: Les 2 javascript w2

Pop-UpConfirm

Page 9: Les 2 javascript w2

Pop-UpPrompt prompt(“text","defaultvalue");

Page 10: Les 2 javascript w2

Functions function functionname(var1,var2,...,varX){some code}

The parameters var1, var2, etc. are variables or values passed into the function. The { and the } defines the start and end of the function.Note: A function with no parameters must include the parentheses () after the function name.

Note: Do not forget about the importance of capitals in JavaScript! The word function must be written in lowercase letters, otherwise a JavaScript error occurs! Also note that you must call a function with the exact same capitals as in the function name.

Page 11: Les 2 javascript w2

FunctionsReturn

Page 12: Les 2 javascript w2

FunctionsBrowserdetectie

Page 13: Les 2 javascript w2

FunctionsBrowserdetectie 2

Page 14: Les 2 javascript w2

Opdracht !

Experimenteren met de code !