CSCI 351: Internet Programming

Final Exam.     Due: Wed, Jul 29

Please upload your work on Canvas as a single ZIP archive ex3.zip before midnight of the day above.

Your scripts should be designed for Internet Explorer.

You may use books and other materials for making these problems in class and at home, but not a human help.
Also, it is not allowed to discuss the problems or solutions with your classmates before the exam due.

  1. (30 points)   Design a JavaScript script that has a button and displays the current time (only hours and minutes, no seconds) in the browser's title bar. Clicking the button should switch the displayed time format between am/pm and the military one.
    For example, 8:24am and 8:24pm in military format should be displayed as 08:24 and 20:24, respectively. If the current time is 8:24am, Clicking the button two times should modify the title bar in the following sequence: 8:24am -> 08:24 -> 8:24am
    Name the source file Ex3_1.htm

  2. (35 points)   Implement the following game with a computer by using JavaScript. The browser's window should contain two text fields - one for the computer output (field 1) and one for the user input (field 2), and one button. Clicking the button should force the computer to generate a random integer number in the range from 0 to 20 and the game begins. The user has only 4 attempts to guess the generated number.

    The user's input (taken from field 2) is compared with the generated number, which is kept in secret. If the numbers match, the user is winning and the game is over. Field 1 should display "Congratulations!". If the numbers do not match, the computer should write "less" or "more" in field 1 depending on the user's input, thus giving the user a hint for the next guess. If the number is not guessed right after 4 tries, the game is over, the computer is winning and shows the answer in field 1.

    The user's input should be checked for a number and only a valid input (i.e., an integer number in the range 0 - 20) should be accepted. You, as a game developer, are permitted to work out possible missing details of this description according to your own taste.

    (Extra 10 points)   for implementing the game in rounds and displaying the current score (computer vs. user) somewhere on the page. The initial score should be set up to 0:0 after any script reloading. Furthermore, the game should have a button for initializing the score without the script reloading.
    Name the source file Ex3_2.htm
    Hint: To get a random integer number r in the range [0..n), where 0 is inclusive and n is exclusive, you can use the construction

    r = Math.floor(Math.random() * n);

  3. (35 points)   Design a JavaScript script that writes a given text string to the screen so, that the size and color of each character is set up randomly. This effect might be used to make one's headers cooler (in a sense). Use at least 5 different text sizes and at least 7 different colors of your choice.
    Name the source file Ex3_3.htm

Make sure to put all necessary files on the server.