Assignment 6: Deconstruct a Script On Your own

Note! This script has been changed to make it Y2K ready. The method getYear() has been eliminated and getFullYear() was put in it's place. getFullYear() returns the correct four-digit year.

Hi . We've been expecting you.

     As you can see , this assignment is calling you by name. That seems simple enough. There's probably a "document.write" command stuck in the text somehow, right? Well, , there's more. If you haven't already, look up above at the title bar. There's your name again and today's date.

Your assignment once again , is to look at the script that placed that fancy TITLE up there. Here's the script. Deconstruct it. Tell me what each command does. (If you're really feeling adventurous, you can also try and figure out how I got your name in the text so much. No looking at the source code! That would be cheating.)

<SCRIPT type="text/javascript">

var name = 
  prompt("Please write in your first name","")

var d = new Date(); 
var y =  d.getFullYear();  
var m = d.getMonth() + 1;  
var d = d.getDate();

var t =  m + '/' + d + '/' + y + ' ';

("Hi "+name+ " Today's date is " 
+t+ "Thanks for coming");



Here's the answer

Close this window to return to JavaScript Primer