Chapter 7 JavaScript: Introduction to Scripting

Notes

7.16 Write a script that asks the user to enter two numbers, obtains the two numbers from the user and outputs XHTML text that displays the sum, product, difference and quotient of the two numbers. Use the techniques shown in Fig. 7.6
Answer

7.17 Write a script that asks the user to enter two integers, obtains the number from the user and outputs XHTML text that displays the larger number followed by the words "is larger" in an information message dialog. If the numbers are equal, output XHTML text that displays the message "These numbers are equal." Use the techniques shown in Fig. 7.15.
Answer

7.18 Write a script that inputs three integers from the user and displays the sum, average, product, smallest and largest of the numbers in an alert dialog.
Answer

7.19 Write a script that inputs from the user the radius of a circle and outputs XHTML text that displays the circle's diameter, circumference and area. Use the constant value of 3.14159 for π. Use the GUI techniques shown in Fig. 7.6. [Note: You may also use the predefined constant Math.PI for the value of π. This constant is more precise than the value 3.14159. The Math object is defined by JavaScript and provides many common mathematical capabilities.] Use the following formulas (r is the radius): diameter=2r, circumference=2πr, area=πr2.
Answer

7.26 Write a script that reads five integers and determines and outputs XHTML text that displays the largest integer and the smallest integer in the group. Use only the programming techniques you learned in this chapter.
Answer

7.27 Write a script that reads an integer and determines and outputs XHTML text that displays whether it is odd or even. [Hint: Use the modulus operator. An even number is a multiple of 2. Any multiple of two leaves a remainder of zero when divided by 2.]
Answer

7.28 Write a script that reads in two integers and determines and outputs XHTML text that displays whether the first is a multiple of the second.
Answer

7.29 Write a script that inputs five numbers and determines and outputs XHTML text that displays the number of negative numbers input, the number of positive numbers input and the number of zeros input.
Answer

 

Back to Deitel Home