Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Pls send me ans if you know..dont put any kind of answers pls..thanks in advance.. In this assignment you will use the prompt() function to
Pls send me ans if you know..dont put any kind of answers pls..thanks in advance..In this assignment you will use the prompt() function to gather a number from your user. The user will enter a number representing the radius of a circle measured in centimeters. Your JavaScript will determine the area of the circle using the following formula:
area = Pi (3.14) times the radius squared
or
A = ? R2
- Create a Web (.html) page named area.html and an external JavaScript (.js) file named areaCalc.js
- Use a script element in your Web page that will link it to your external JavaScript file
- In your external JavaScript file, use the prompt() function to gather the viewer's radius in centimeters. You may assume that the viewer will enter a real number. Don't forget to use the parseFloat function as you did in your last assignment to ensure that you populate your area variable with numeric data
- Assign the user's radius number to a variable name "myRadius"
- Create a function named calculateArea() that will calculate the area of the circle. This function must not contain the prompt() function
- Create a function parameter named "myArea" for your calculateArea() function
- Use an alert() function to call your calculateArea() function. This function call must pass the user's radius value (the "myRadius" variable) to the calculateArea() function parameter so that your function has the information it needs to calculate the area of the circle
- Use the toFixed() method to limit your area value to a single (1) decimal
- Return the calculated area to the alert() function where the function call originated
- The alert() function must display the results like this:
A circle with a X centimeter radius has an area of Y square centimeters.
X represents the number entered by the user.
Y represents circle area based on the user input.
Test your code. Make sure it works with repeated radius entries.
Hint: Place your calculateArea() function at the top of the page so that it is read first by the browser. Your prompt and alert functions should be coded after and outside of the calculateArea() function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started