0% found this document useful (0 votes)
5 views2 pages

I254 Fall 2003 Homework 2: Javascript 20/01/2004

Uploaded by

Ali Husseini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

I254 Fall 2003 Homework 2: Javascript 20/01/2004

Uploaded by

Ali Husseini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

I254 Fall 2003 Homework 2: JavaScript 20/01/2004

Exercise 1: Javascript HTML Table generation


Create an HTML document that includes some Javascript that makes the following happen: When the
document is initially loaded, a prompt appears and asks the user for an integer. (Use window.prompt
to prompt for and get an integer). The document will then include an HTML table of the squares and
cubes of integers from 0 to n where n is the value entered by the user. If the user entered the
value 5, the table might look like this:
Number Square Cube
0 0 0
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
Exercise 2: Javascript arrays/functions
Write a Javascript function named gameboard(). This function should create an 8x8 checkerboard (by
calling document.write). Each "cell" in the game board should be 20 pixels wide and 20 pixels high.
The colors of the board are passed to your gameboard function as a 2 element array. Your function
could be called like this: gameboard(["black","red"]), - this means you should use the colors "black"
and "red" when drawing the board. Some example calls to your function and the expected output:

gameboard(["black","red"]); gameboard(["green","yellow"]);

Hint: use cellspacing=0 in the table tag to eliminate any space between
the different cells of the table. <Table cellspacing = 0>

Exercise 3: String Manipulation:


Write a script that inputs a telephone number as a string in the form (555) 555-5555. The script should
use String method split to extract the area code as a token, the first three digits of the phone number
as a token and the last four digits of the phone number as a token. Display the area code in one text
field and the seven-digit phone number in another text field.

Exercise 4: OnClick() use:


Write a javascript code to produce the following simple calculator. Just click the numbers and the
operators and use the "=" button to calculate!

You might also like