JavaScript

Tuesday April 8, 2025
updated: April 10, 2002

 
Home
Getting Started
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Resources
Credits

 

 


Lesson 8 Example 3: Switch Statement

You will receive a different greeting depending on the day it is.

Put in body:

<script type="text/javascript">
var d = new Date()
theDay=d.getDay()
switch (theDay)
{
case 5:
alert("Finally Friday")
break
case 6:
alert("Super Saturday")
break
case 0:
alert("Sleepy Sunday")
break
default:
alert("I'm really looking forward to this weekend!")
}
</script>

Note that Sunday=0, Monday=1, Tuesday=2, Wednesday=3 etc.


© 2002 Tracy Johnson