Button 1



JavaScript Homework #1Create an HTML file with two buttons ("official" buttons that use the <button> tag). Below the first button should be 2 paragraphs, and below the second button there should be 4 paragraphs. Each paragraph should have its own ID value. After reading the problem description below, come up with appropriate (descriptive) IDs for the 6 paragraphs. HTML: 8 pointsButton 1The text on the button should be Convert Case. When the button is clicked, call a JavaScript function that does the following (10 points):Prompt the user for a string. Convert each character in the string to its opposite case. That is, convert all lower-case letters to upper-case and convert all upper-case letters to lower-case. You MUST use bitwise operators. Note that all uppercase letters are between 'A' and 'Z' and all lower-case letters are between 'a' and 'z'. You may want to check the ASCII code and look at both the decimal and binary values of the uppercase and lowercase letters. NOTE: There is one bitwise operator that, when applied to a character, can convert a lower case character to uppercase, and convert an upper-case character to lower case. How you solve the problem doesn't matter, as long as you use bitwise operators.Any character that is not a letter should remain unchanged.Display the original string with a label (e.g. "Original string: FOUR score and SEVEN years ago!") in the first paragraph at the bottom of the web page. Note that the label "Original string: " should always be in the first paragraph, even before the button is clicked.Display the converted string with a label (e.g. "New string: four SCORE AND seven YEARS AGO!") in the second paragraph at the bottom of the web page. Note that the label "New string: " should always be in the second paragraph, even before the button is clicked.Button 2The text on the button should be Compute Payment. When the button is clicked, call a JavaScript function that does the following. We will not do any error checking of input values (15 points):Prompt the user for a loan amount (a floating point value).Prompt the user for an annual interest rate (a floating point value) as a number from 0 to 100, not as a decimal fraction from 0 to 1. For example 5.15% would be entered as 5.15, not 0.0515.Prompt the user for the number of years to repay the loan. We will assume that this is an pute the monthly payment on the loan. Look up the formula for computing the payment on a loan on the Internet. Here is one example you can use to see if you are computing the payment correctly. If the loan amount is $50,000 and the annual rate is 12.00% and the number of years is 30, the monthly payment is $514.31 (rounded off).Put the three input values in the third, fourth, and fifth paragraphs at the bottom of the page. Put the payment in the sixth paragraph. Put labels before each number!Format the payment with 2 decimal places.You may find the following helpful:For input and output: window.prompt(), alert(), getElementId, innerHTMLBitwise operators for converting the case of a letter. Note that the bitwise operators operate on integers, not on strings, characters, etc. You will need to convert each character into a 32-bit integer before applying any bit operators. Bitwise operators: & | ^ ~ << >> >>>There are some useful String methods for converting characters to their ASCII codes (numbers) and for converting numbers (ASCII codes) to characters: fromCharCode, charCodeAt, charAt. Note that fromCharCode is a static function and charCodeAt and charAt are member functions.Methods for converting one data type to another (converting strings to floating point and integer numbers, and converting floating point and integer numbers back to strings for output). parseFloat and toFixed() are two functions you will need.CSSApply some styling to the HTML document. Size the buttons, color their background, color their text. Both words on each button must fit on one line. Make the default font a sans-serif font and increase its size (7 points).Below are before and after screen shots. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download