When I remove the getday() method, the string is displayed, but when I add the method, even the string is not displayed.
The same thing happens in Firefox
Antivirus is disabled
Code :
<html>
<body>
<script type="text/javascript">
d = new Date();
switch(d.getday()){
case 0:
day = "Sunday";
break
case 1:
day = "Monday"
break
case 2:
day = "Tuesday"
break
case 3:
day = "Wednesday"
break
case 4:
day = "Thursday"
break
case 5:
day = "Friday"
break
case 6:
day = "Saturday"
break
document.write("<b> today is: ", day);
}
</script>
</body>
Result :
enter image description here
I searched about this problem, but only one person had the same problem because he/she copied the codes from somewhere and the problem was solved by writing the code. I did not copy the code, so… please help me.
2
Answers
I did not follow the camelcase writing rules in calling the getday() method getDay() is true.
there were a few errors that I found in the code you provided.
d = new Date();
, but if you declare a variable, you’ll have to use keywords likeconst
,let
, orvar
. Same with theday
variable.document.write()
statement is inside theswitch
statement.after resolving these two errors, here is the updated version of the code: