Internet & World Wide Web: How to Program by Deitel and Deitel Javascript Hands-On Lesson 01
Use a Text Editor The file you create must be plain text Not a Word document Not Rich Text Format (.rtf) Just text We will give an extension of.html Notepad bare bones Visual Studio s text editor much better Many other tools some are WYSIWYG
Getting Started t with Visual Studio Open Visual Studio File Open Web Site Open MyWebSite that contains all your other in-class pages OR File New Web Site (to start from scratch) Choose the Empty Web Site Template
Getting Started t with Visual Studio In Solution Explorer, right-click on the name of the solution and add an images folder if there is not one already In Solution Explorer, right-click on the name of the solution Select Add New Item Select the HTML Page template Click Add Name the page whatever you want
Problem 6.19 From Deitel Text Pages 231-232 6.19 Write a script that gets from the user the radius of a circle and outputs XHTML text that displays the circle's diameter, circumference and area.
Flowchart of Solution Algorithm Create a flowchart of the solution process
Pseudo Code of Solution Process Write pseudo code or detailed instructions for the solution process 1. Declare the variables you will need a variable to hold the value of the radius that the user inputs. The user will input a value, but the input will be treated as a string a variable to hold the numerical value of the radius that will be used in the calculation a variable to hold the value of the diameter that you calculate based on the user's input value of radius a variable to hold the value of the circumference that you calculate based on the user's input value of radius a variable to hold the value of the area that you calculate based on the user's input value of radius 2. Create a prompt window that asks the user to enter a value for the radius of a circle. The statement should save the value in the variable you set up for the string input value of the radius 3. Convert the input string value of the radius to the type float (a javascript function you can use for that purpose p is parsefloat) 4. Compute the circumference 5. Use the Math.round function to round the circumference value computed to tenths or hundreths 6. Write a javascript statement to compute the area 7. Use the Math.round function to round the area value computed to tenths or hundreths 8. Write 3 javascript statements to output the results
Set up the Page Structure for the Script Add a <script></script> element to the <head></head> element of the page that will call the script
1 Declare the Variables You need: a variable to hold the value of the radius that the user inputs. The user will input a value, but the input will be treated as a string a variable to hold the numerical value of the radius that will be used in the calculation a variable to hold the value of the diameter that you calculate based on the user's input value of radius a variable to hold the value of the circumference that you calculate based on the user's input value of radius a variable to hold the value of the area that you calculate based on the user's input value of radius
2 Get Input from User Create a prompt window that asks the user to enter a value for the radius of a circle. The statement should save the value in the variable you set up for the string input value of the radius. Convert the input string value of the radius to the type float (a javascript function you can use for that purpose is parsefloat)
3 Process or Calculate Compute the circumference Use the Math.round function to round the circumference value computed to tenths or hundreths Write a javascript statement to compute the area Use the Math.round function to round the area value computed to tenths or hundreths
4 Show Output Write 3 javascript statements to output the results
Save Build Start w/o Debugging g to Test The browser renders the content with the structure specified by the XHTML markup and the embedded Javascript code
Results!
Other Ways Many similar resources available Use Page View Source option in IE to examine the JavaScript used Some sites use php a server side scripting language or some other server-side language Can you tell which sites use JavaScript and which use a serverside program? Which of these calculators do you like best? Why? Can you find one you like better? http://math.about.com/libra ry/blcirclecalculator.htm http://www.csgnetwork.co m/circle_sphere_area_calc ulator.html http://easycalculation.com/ area/circle.php p http://www.basicmathematics.com/circumfe rence-calculator.html
Internet & World Wide Web: How to Program by Deitel and Deitel Javascript Hands-On Lesson 01