CCSF Spring 2010 / CNIT 133 Homework 7 - Objects


Link to... Description
Part 1 Create a webpage that contains a script that defines four functions (using Math method floor) to round a number in various ways:
  1. roundToInteger( number )
  2. roundToTenths( number )
  3. roundToHundredths( number )
  4. roundToThousandths( number )
For each value read, your script should display the original value, the number rounded to the nearest integer, the number rounded to the nearest tenth, the number rounded to the nearest hundredth, and the number rounded to the nearest thousandth. Use a form input box for user input and a textarea to display the output.
Part 2 Create a webpage that contains a script using a form that inputs several lines of text and a search character and uses the String method charAt to determine the number of occurrences of the search character within the text. Use a form textarea for the text and a form input box for the search character. If the search character is found within the text, display the number of occurrences of the search character in another form input box or a textarea. If the search character is not found within the text then display within a new window (using the window.open method), the message, 'Search character not found in text string!' along with the search character. Your new window should be a width of 300 pixels, height of 100 pixels, and be centered approximately over the original page.
Part 3 Create a webpage that does the following:
  1. Using toString() and toLocaleString() for the Date object, write the current date and time in both formats. Using the getTimezoneOffset(), write the hours difference between EST (Eastern Standard Time) and UTC. Note: EST is 3 hours ahead of PST (Pacific Standard Time).
  2. Input 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 3 digits of the phone number as a token, and the last 4 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.
Part 4 Create a webpage that contains form input password fields for the user's name and password and a submit and reset button. (The correct username should be rosebud and the correct password should be komodo)
  1. When the user first opens the webpage:
    1. The user should enter an incorrect username and/or password and click the submit button, which should call a validation script function that should alert an error message and then stay on the current page.
    2. Then the user should enter the correct username and password and click the submit button which will again call the validation script function and do the following:
      1. alert a message that the username and password are correct.
      2. call a script function that will set a cookie for the username of rosebud. (set the cookie to expire in 30 days)
      3. transfer location to another webpage.

  2. When the user returns to the original page within 30 days with the cookie already set, then, when the user clicks in the username form field, use onfocus to call a script function that will:
    1. check to see if the cookie has been set and if so call another script function to get the cookie, which will contain the username of rosebud and then return to the check cookie script function.
    2. alert the welcome message, 'Welcome again rosebud'.
    3. automatically display the username of rosebud and the password of komodo in the form input fields.
    4. click the submit button to ensure that the validation of username and password are correct.


Valid XHTML 1.0 Strict Valid CSS!