JavaScript Exercise #1

PHOTO EMBED

Sat Dec 26 2020 11:59:32 GMT+0000 (UTC)

Saved by @Javkhlantugs ##javascript

/* Write a JavaScript program to display the 
current day and time in the following format.
Today is : Tuesday. 
Current time is : 10 PM : 30 : 38 */ 

var today = new Date(); 
var day = today.getDay(); 
var daylist = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
document.getElementById("demo").innerHTML = "Today is : " + daylist[day] + "." 
//console.log("Today is : " + daylist[day] + "."); 

var hour = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds(); 
var prepand = (hour >= 12)? "PM ":" AM "; 
hour = (hour >= 12)? hour - 12: hour; 
if (hour===0 && prepand=== "PM ")
{
if (minute===0 && seconds===0)
{
hour=12; 
prepand=' Noon';
}
else 
{
hour=12; 
prepand= ' PM'; 
} 
}
if (hour===0 && prepand===' AM')
{
if (minutes===0 && second===0)
{
hour=12;
prepand=' Midnight';
}
else 
{
hour=12;
prepand= ' AM';
}
}
//console.log("Current Time: " + hour + prepand + " : " + minutes + " : " + seconds); 
document.getElementById("demo1").innerHTML = "Current Time: " + hour + prepand + " : " + minutes + " : " + seconds 
content_copyCOPY