HW 5

in-class section: due 5/3 (by midnight)
DL section: due 5/4 (by midnight)

We talked about JavaScript, using material from chapters 4 and 5 of the book (excluding document.write). I have uploaded the class examples, please browse them and look at the code to see why and how they work. Play around with them (try different text, different colors, etc.).

1. [JavaScript, 15pt] Write a web-page that prompts the user for their first name, say Johnathan, and their favorite type of music, say Jazz, and then brings up a pop-up box saying "So you like Jazz, Johnathan, do you?" (with Jazz and Johnathan replaced by whatever the used entered, of course).

2. [JavaScript, 15pt] Create a web-page with a 2 * 2 table containing colors of your choice (be creative, don't use red, green, yellow, blue, purple, pink, black, white), for example, your table could look as follows (use style sheets to set the background color of the table cells).


Now when a user clicks on a particular cell, the background color of the page should change to the cell color. Hint: use a separate onclick eventhandler with each table cell. In the Javascript you will need to use single quotes around the color not double-quotes, e.g.

      onclick = "document.bgColor = 'red';"

3. [JavaScript, 15pt] Complete the currency converter we began in class: the user should be able to input the amount in Dollars, and then be told the corresponding amount in Euros. For the conversion use a variable convertDollarEuro which should be set using:

    convertDollarEuro = 0.802939;

4. [Extra Credit, 5pt]  Read Alice in Wonderland and Through The Looking Glass. If you don't have time right now to read all of it,
concentrate on the following dialogue between Alice and the Knight from Through the Looking Glass:

  `You are sad,' the Knight said in an anxious tone: `let me sing you a song to comfort you.' 
  `Is it very long?' Alice asked, for she had heard a good deal of poetry that day. 
  `It's long,' said the Knight, `but it's very, very beautiful. 
      Everybody that hears me sing it---either it brings the tears into their eyes, or else---' 
  `Or else what?' said Alice, for the Knight had made a sudden pause. 
  `Or else it doesn't, you know. The name of the song is called "Haddocks' Eyes".' 
  `Oh, that's the name of the song, is it?' Alice said, trying to feel interested. 
  `No, you don't understand,' the Knight said, looking a little vexed. 
     `That's what the name is called. The name really is "The Aged Aged Man".' 
  `Then I ought to have said "That's what the song is called"?' Alice corrected herself. 
  `No, you oughtn't: that's quite another thing! The song is called "Ways and Means": 
      but that's only what it's called, you know!' 
  `Well, what is the song, then?' said Alice, who was by this time completely bewildered. 
  `I was coming to that,' the Knight said. 
     `The song really is "A-sitting On a Gate": and the tune's my own invention.' 

   So saying, he stopped his horse and let the reins fall on its neck: then, 
   slowly beating time with one hand, and with a faint smile lighting up his 
   gentle foolish face, as if he enjoyed the music of his song, he began. 

    Explain what this has to do with variables.

5. [homework.html, 5pt] Remember to place your homework in the hw5 folder, and add a link to it on your homework.html page.

Marcus Schaefer
Last updated: April 26th, 2006.