Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Javascript Complications


ghost's Avatar
0 0

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.


clone4's Avatar
Perl-6 Wisdom Seeker
0 0

all you need is the script tag with .html file extension. to the theDay variable, you don't enter it, it gets the actual date… research new Date&getDay functions to understand it


ghost's Avatar
0 0

thanks i'll work on itB)