Assignment #2:

I had a heck of a time finding this script online because there was no script on the JavaScript Goodies webpage, as indicated in the book. There was, however, a note posted in the answer page: "getYear()" has been updated to "getFullYear()" because of it now being the year 2000"

HTML file: Displayed by browser:
<BODY>

<SCRIPT type="text/javascript">
/*...x <== I've never seen this before...*/
dothis = new Date()
month = dothis.getMonth()
month = (month * 1) + 1
day = dothis.getDate()
year = dothis.getFullYear()
/*document.wrte(" ",month,"/",day,"/",year," ") <== mispelled write*/
document.write(" ",month,"/",day,"/",year," ") // CORRECTED LINE
</SCRIPT>

</BODY>

The answer: The script is supposed to display today's date, although I didn't know that at first because the browser displayed a blank page with the original script. I encountered two errors, which is what I was supposed to do. However, the Developer's Console only shows one error at a time, which sucks! I only used Firefox to debug the script. The first report was "SyntaxError: expected closing parenthesis, got identifier", pointing me to the "dothis = new Date()" line, which is just below the "...x" (the author had stuck that in for fun). Once I commented out the "...x" line, I ran the Console again and Firefox then reported a new error "TypeError: document.wrte is not a function", and pointed me to that line.

What I have learned:

  1. Rerun the Console after each error you fix
  2. If the browser doesn't understand something, it might think the next line is the error
  3. If you google long enough, you will find what you are looking for

BackTable of ContentsNext