Question: JavaScript Square and Circle The material that you are only allowed to use on this subject are: 1 . Data types 2 . Variables, expressions,
JavaScript
Square and Circle
The material that you are only allowed to use on this subject are:
Data types
Variables, expressions, and assignment statements
Functions
If statements
The alert, prompt, and confirm window functions.
The program requirements are:
Type in JavaScript statements between the tags in the body that will do the following list of functions with the descriptions that are below the list:
main, calcAreaOfSquare, calcAreaOfCircle, displayResultsOfSquare, displayResultsOfCircle
The description of the main function:
Prompt the user to make a selection of if they want to find the area of a square or if they want to find the area of a circle.
Convert the string entered to an integer.
If they entered do the following:
Ask them to enter a positive number that represents the length of a side of the square.
Convert the string entered to a floatingpoint number.
If they entered a positive number, do the following:
Call a method named calcAreaOfSquare that will calculate and return the area of a square. This method takes the side as a parameter.
Call a method named displayResultsOfSquare that will display the results. This method takes the side and the area as parameters.
else, do the following:
Write a message to the browser wrapped in HTML paragraph tags
that state that the number entered by the user is not positive. else if they entered do the following:
Ask them to enter a positive number that represents the radius of the circle.
Convert the string entered to a floatingpoint number.
If they entered a positive number, do the following:
Call a method named calcAreaOfCircle that will calculate and return the area of a circle. This method takes the radius as a parameter. Call a method named displayResultsOfCircle that will display the results. This method takes the radius and the area as parameters.
else, do the following:
Write a message to the browser wrapped in HTML paragraph tags that state that the number entered by the user is not positive.
else do the following:
Write a message to the browser wrapped in HTML paragraph tags that state that the choice was invalid.
The description of the calcAreaOfSquare function:
This function takes one parameter that represents the side of a square and returns a value representing the area of the square. The area of a square is determined by the following formula:
area side side
The function returns the area calculated.
The description of the calcAreaOfCircle function:
This function takes one parameter that represents the radius of a circle and returns a value representing the area of the circle. The area of a circle is determined by the following formula:
area radius radius The function returns the area calculated.
The description of the displayResultsOfSquare function:
This function takes the side and area of the square as parameters and writes the results to the browser in the following format:
Length of side: whatever the length is
Area of square: whatever the area is Display the numbers with only one decimal place.
The description of the displayResultsOfCircle function:
This function takes the radius and area of the circle as parameters and writes the results to the browser in the following format:
Radius of circle: whatever the radius is
Area of circle: whatever the area is Display the numbers with only one decimal place.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
