-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thorarinn Sofusson
authored and
Thorarinn Sofusson
committed
Aug 7, 2017
0 parents
commit 2f64e3b
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function getWeekDay(date){ | ||
var weekday; | ||
// use array with day names | ||
switch (date.getDay()) { | ||
case 0: | ||
weekday = "Sunday"; | ||
break; | ||
case 1: | ||
weekday = "Monday"; | ||
break; | ||
case 2: | ||
weekday = "Tuesday"; | ||
break; | ||
case 3: | ||
weekday = "Wednesday"; | ||
break; | ||
case 4: | ||
weekday = "Thursday"; | ||
break; | ||
case 5: | ||
weekday = "Friday"; | ||
break; | ||
case 6: | ||
weekday = "Saturday"; | ||
break; | ||
} | ||
return weekday; | ||
} | ||
|
||
function getCurrentTimeInUSFormat(date){ | ||
var timeString; | ||
var hour = date.getHours(); | ||
|
||
if (hour >= 12) { | ||
timeString = (hour % 12).toString() + " PM"; | ||
} | ||
// double or triple equals? | ||
else if (hour == 0) { | ||
timeString = "12 AM"; | ||
} | ||
else { | ||
timeString = hour.toString() + " AM"; | ||
} | ||
|
||
timeString = timeString + " : " + today.getMinutes() + " : " + today.getSeconds(); | ||
return timeString; | ||
} | ||
|
||
var today = new Date(); | ||
|
||
alert("Today is : " + getWeekDay(today)); | ||
alert("Current time is : " + getCurrentTimeInUSFormat(today)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
js exercises for warmup | ||
|
||
http://www.w3resource.com/javascript-exercises/ |