Javascript Complications
Hello, I am entirely new to javascript and I have been learning it mainly from www.w3schools.com. Since I have learnt VB6.0 and HTML (and SQL) understanding the syntax and the logic was very easy. But I don’t understand how to apply it.
Consider example (as given in www.w3schools.com)
//You will receive a different greeting based
//on what day it is. Note that Sunday=0,
//Monday=1, Tuesday=2, etc.
var d=new Date();
theDay=d.getDay();
switch (theDay)
{
case 5:
document.write("Finally Friday");
break;
case 6:
document.write("Super Saturday");
break;
case 0:
document.write("Sleepy Sunday)";
break;
default:
document.write("I'm looking forward to this weekend!");
}
</script>
So do I need to introduce the <html> </html> and the <body> </body> and run it as a ‘.html’ file or should I save it as a ‘.js’
The former gives me the message “I'm looking forward to this weekend!” in the browser page while the latter gives me a message box showing a lot of compilation errors.
And one more thing where do I enter the value of ‘the Day’ variable
I have these doubts for all the sample scripts. Please guide me. Thank you very much for your time and effort.