CCSF Spring 2010 / CNIT 133 Homework 7 - Objects
Create a webpage that contains a script that defines four functions (using Math method floor)
to round a number in various ways:
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.
- roundToInteger( number )
- roundToTenths( number )
- roundToHundredths( number )
- roundToThousandths( number )
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.
Create a webpage that does the following:
- 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).
- 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.
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)
- When the user first opens the webpage:
- 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.
- 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:
- alert a message that the username and password are correct.
- call a script function that will set a cookie for the username of
rosebud. (set the cookie to expire in 30 days)
- transfer location to another webpage.
- 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:
- 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.
- alert the welcome message, 'Welcome again rosebud'.
- automatically display the username of rosebud and the password of komodo in the form input fields.
- click the submit button to ensure that the validation of username and password are correct.