Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to get this java code to work in html? I looked through the entire coding an

ID: 3938272 • Letter: H

Question

How to get this java code to work in html? I looked through the entire coding and found no mistake, but the clock won't show up on the browser.

<script type="text/javascript">
tday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
tmonth=newArray("January","February","March","April","May","June","July","August","September","October","November","December");
function GetClock(){var d=new date();
var nday=d.getDay(),nmonth=d.getMonth(),nyear=d.getYear();
if(nyear<1000)nyear+=1900;
var nhour=d.getDay(),nmin=d.getMinutes(),nsec=d.getSeconds();
if(nmin<=9)nmin="0"+nmin
if(nsec<=9)nsec="0"+nsec;
document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+ndate+",
"+nyear+" "+nhour+":"+nmin+":"+nsec+";
}
window.onload=function(){GetClock();
setInterval(GetClock,1000);
}
</script>
<div id="clockbox"></div
>

Explanation / Answer

There are some errors in the given code. Please find below the modified corrected code. Please see the comments for any explanations :

<script type="text/javascript">
tday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
tmonth=new Array("January","February","March","April","May","June","July","August","September","October","November","December"); //space is required after new keyword
function GetClock(){var d=new Date(); //Date class it should be
var nday=d.getDay(),nmonth=d.getMonth(),nyear=d.getYear();
if(nyear<1000)nyear+=1900;
var nhour=d.getDay(), nmin=d.getMinutes(), nsec=d.getSeconds();
if(nmin<=9)nmin="0"+nmin
if(nsec<=9)nsec="0"+nsec;
document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+nday+" "+nyear+" "+nhour+":"+nmin+":"+nsec; //ndate is not declared, it should be nday
}
window.onload=function(){GetClock();
setInterval(GetClock,1000);
}
</script>

-----------------------------------------------------

SAMPLE OUTPUT:


Saturday, November 6 2016 6:00:14

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote