Question: 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

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

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 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.

Deliverables

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!