CMSC 104, Spring 2010
Homework 3
Your First JavaScript Program
Out: Monday, March 29, 2010
Due: Wednesday, March 31, 2010 by 11:59 p.m.
Note: No late projects will be accepted.
The Objective
- To learn to create and run JavaScript programs
- To become familiar with syntax error messages generated by the JavaScript error console.
The Task
- Before you begin working on the assignment, you must set up
your account so that no one else can see your Web page while you
are working on it. You will only be able to access your page
by typing in a username and password. The only people who will
be able to access your page are you, me and the graders for the
class. You *must* do this step before you begin working on your
page. Note that when you type in your password for the script
nothing will show up on the screen, just type it and hit enter.
Type the following command at the linux prompt:
linux2[12]% /afs/umbc.edu/users/d/o/dondim1/pub/setup104
You should see something similar to the following:linux2[12]% /afs/umbc.edu/users/d/o/dondim1/pub/setup104 Creating new directory: /afs/umbc.edu/users/c/m/cmsc/pub/access Using exising directory: /afs/umbc.edu/users/c/m/cmsc/pub/www Using exising directory: /afs/umbc.edu/users/c/m/cmsc/pub/www/cs104 Using exising directory: /afs/umbc.edu/users/c/m/cmsc/pub/www/cs104/hw3 Using exising directory: /afs/umbc.edu/users/c/m/cmsc/pub/www/cs104/proj1 Using exising directory: /afs/umbc.edu/users/c/m/cmsc/pub/www/cs104/proj2 Using exising directory: /afs/umbc.edu/users/c/m/cmsc/pub/www/cs104/proj3 Using exising directory: /afs/umbc.edu/users/c/m/cmsc/pub/www/cs104/proj4 ********************************************************************* * Please enter a password other than your myUMBC/GL password below. * * This will be the password you need to access your pages online. * ********************************************************************* Creating new password file New password: Re-type new password: Adding password for user cmsc linux2[13]%
- After you run the setup script, you will be asked for a password when you eventually look at your Web page for the assignment in the Web browser.
- For the first part of the assignment, you must complete the program associated with this assignment (a separate handout) by filling in the blanks where pieces of code are missing.
- Look carefully through the entire program before starting to fill in the blanks. It is more straightforward than you think. For example, we actually refer to specific variable names later on in the body, so you don't really have a choice in the naming of the variables declared in the "var ________" lines, near the top of the program.
- Use common sense; for example, the test in the "else if" part could syntactically be exactly the same as in the first "if", but that is obviously not what we want!
- After filling in the blanks, you are ready to move on to the second
part of the assignment.
- Change into your hw3 directory. (
cd ../pub/www/cs104/hw3
). - Use xemacs (
xemacs hw3.html
) to type in the JavaScript program. You should type the program in INCREMENTALLY!! Type it in EXACTLY AS SHOWN, including all spacing and indentation. Some exceptions:- Insert YOUR name as the author.
- Insert YOUR username.
- Insert a heading of your choice on the page where it says "Heading for Your Page."
- You may add a <style>...</style> section to the head section of the page if you'd like to change the colors, fonts, etc.
-
The program must be called
hw3.html
. It should be located in yourpub/www/cs104/hw3/
directory. The grader will access your page directly from the given directory. - After you have created the initial part of this program in xemacs on the campus Linux machine, you can then finish the assignment using other editors, such as Notepad++
- Change into your hw3 directory. (
- Some hints/advice:
Using the JavaScript Error Console
- The JavaScript error console will help you find errors in your program. To run the error console in Firefox, go to Tools->Error Console. It will bring up a separate window containing the error console. You should use the Clear button to clear the error console and then refresh your web page. If there are any problems with your JavaScript code, they should show up in the error console.
Sample Run
- The URL for your page will be http://userpages.umbc.edu/~username/cs104/hw3/hw3.html, where username is your GL/myUMBC username. You should refresh the page several times and run the program with different sets of values. You can assume that the user will only enter numbers as input. Here are some sample screenshots of the program:
User entering first number
User entering second number
Final results page