Practical 3

Open text Document or any text editor and type like below. 

 

HTML and JS(javaScript)

<html>
    <head>
        <title>Practical 3</title>
    </head>
    <body>
        <h1 id="setTime" onclick="liveTimeAndDate()"></h1>
        <h2 id="setDate" onclick="liveTimeAndDate()"></h2>
        <script>
            function liveTimeAndDate(){
                let now = new Date;
               
                let hour = now.getHours();
                var midday = (hour>=12)? "PM":"AM";

                hour = (now==0) ? 12:((hour>12)?(hour-12):hour);
                hour = (hour<10) ? "0"+hour: hour;
               
                let min = now.getMinutes();
                min = (min<10)? "0"+min:min;
               
                let sec = now.getSeconds();
                sec = (sec<10)?"0"+sec:sec;
               
               
                document.getElementById("setTime").innerHTML=hour+":"+min+":"+sec+" "
                                                                +midday;
               

                let day = now.getDate();
                let weekday = now.getDay();
                let days = ["Sunday","Monday","Tuesday","Wednesday","Thursday",
                            "Friday","Saturday"];
                let nameOfDay = days[weekday];
               
                let month = now.getMonth();
                let months = ["January","February","March","April","May","June","July"
                            ,"Augest","September","October","November","December"];
                let nameOfMonth = months[month];

                let year = now.getFullYear();
                document.getElementById("setDate").innerHTML = day+" "+nameOfDay+" "+
                                           "/"+(month+1)+" "+nameOfMonth+" "+"/"+year;
           
            }

            setInterval(liveTimeAndDate,1000);
        </script>
    </body>
</html>


Then go to the "File" tab and "Save as". After that "File name: p3.html" and "Save as type: All files (*.*)". Then after that Click on the save button.

The output of this practical 3


To Visit or Download the source code                                                                        See the results online



Go to Practical 4