Embed
Email

JavaScript

Document Sample

Shared by: qinmei liao
Categories
Tags
Stats
views:
0
posted:
11/1/2011
language:
Indonesian
pages:
7
Pertemuan 3

 If statement

 If else

 If , else if, else statement

 Switch statement



if (condition)

{

var d = new Date();

var time = d.getHours(); code to be executed if condition is true

if (time Good morning");

}





This example demonstrates the If statement.





If the time on your browser is less than 10,

you will get a "Good morning" greeting.







if (condition)





{

var d = new Date();

var time = d.getHours();

code to be executed if condition is true

if (time Good morning");

} {

else

{ code to be executed if condition is not true

document.write("Good day");

} }





This example demonstrates the If...Else statement.





If the time on your browser is less than 10,

you will get a "Good morning" greeting.

Otherwise you will get a "Good day" greeting.









if (condition1)

{



var d = new Date(); code to be executed if condition1 is true

var time = d.getHours(); }

if (timeGood morning"); {

}

else if (time>=10 && timeGood day");

} else

else {

{

document.write("Hello World!"); code to be executed if condition1 and condition2 are not true

} }





This example demonstrates the if..else if...else statement.







switch(n)



{

var d = new Date(); case 1:

theDay=d.getDay();

switch (theDay) execute code block 1

{ break;

case 5:

document.write("Finally Friday"); case 2:

break; execute code block 2

case 6:

document.write("Super Saturday"); break;

break; default:

case 0:

document.write("Sleepy Sunday"); code to be executed if n is different from case 1 and 2

break; }

default:

document.write("I'm really looking forward to this weekend!");

}



This JavaScript will generate a different greeting based on what day it is. Note that Sunday=0, Monday=1, Tuesday=2, etc.





 Buat program JavaScript yang akan melaporkan ;

 Nama hari ini

 Tanggal hari ini

 Waktu sekarang

▪ Pagi

▪ Siang

▪ Sore

▪ Malam



Related docs
Other docs by qinmei liao
Q CMA ExperienceRequirement
Views: 0  |  Downloads: 0
Lipid Learning Activity
Views: 0  |  Downloads: 0
MATERIAL SAFETY AND DATA SHEETS
Views: 2  |  Downloads: 0
Financial Planning The Ties That Bind
Views: 0  |  Downloads: 0
Inflammatory Pain
Views: 4  |  Downloads: 0
Group goal setting workshop
Views: 0  |  Downloads: 0
MEETINGS REPORT ACTION SHEET
Views: 1  |  Downloads: 0
LYMPHOMA RESEARCH FOUNDATION
Views: 0  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!