You hand in this assignment by showing it to the lecturer when it is completed. This assignment contains some syntax errors you should correct and it works well when you can run it without an error message been displayed and the 10 randomly chosen numbers analyzed correctly.
Please refer to this page for information on how to work on your assignment.
Most of a web page is written in Hypertext Markup Language (HTML). But this page contains also some parts in JavaScript. Note that there is an other programming language with the name Java, but JavaScript shares with it just the name. These parts are mixed into the HTML page. In order to make it easier for you to learn to program with JavaScript, you receive almost ready programs. So you do not need to learn HTML.
Follow the link for an introduction to JavaScript.
This exercise is quite easy. Its main task is to teach you to find typing errors in a program, this process is called debugging. The given program has errors in seven lines and you should find and correct them all; some of the faulty statements are superfluous and can be deleted, others have to be corrected.
Your web browser provides help for finding JavaScript bugs. You have two browsers available in the lab: Mozilla Firefox 17 and Internet Explorer 7. We recommend you to choose Firefox, as it strongly adheres to web standards and its version is quite up-to-date, unlike Internet Explorer. However instructions are given for both.
You can use two different built-in tools in Firefox. They should prove more than enough for the assignments.
The first one is the Error Console accessible fromTools,
Web Developer,
Error Console. It opens a new window in which JavaScript (and other) errors are displayed.
The second tool, which we recommend, is the Web Console. You can enable
it for a given page from Tools
, Web Developer
,
Error Console
(or Ctrl+Shift+K on your keyboard). You can
restrict the kind of message to Javascript ones and leave it embedded
into the page rather than having another window cluttering your screen.
Both tools also provide you with an inline JavaScript interpreter so you can type some code and immediately see the results.
Having done this, you should on the one hand edit the file with the text
of this page and on the other hand press the Reload Current Page
button of the browser to see the effect of what you are doing. Please
note that reloading the page does not clear the previous error messages.
These explanations have been verified for Internet Explorer version 7 only, upper versions might have a different layout and/or behaviour. You have to change the default settings:
Toolsand then to the last row
Internet Options.
Internet Optionspops up. Go to the
Advancedentry in the list of subwindows on the top.
Display a notification about every script errorbox (sixth box under the
Browsingentry).
OKin the lowest row to finish.
Having done this, you should on the one hand edit the file with the text
of this page and on the other hand press the refresh
or
reloading
button of the browser to see the effect of what you are
doing. Note that you should view the details of the announced JavaScript
errors to get the line numbers.
The corrected program computes the divisors of 10 randomly chosen numbers between 1 and 99 and then checks whether the chosen number is prime, square or having only one decimal digit. The number and the diagnosis about it are printed out.