Area and perimeter of the rectangle using JavaScript.
In this article we are going to know how Calculate the area and perimeter of the rectangle using JavaScript. In this program, we are going to use prompt() to input data and calculate area and perimeter without using function and event.
Formula
Area=length X Width
Perimeter = 2X(length + width)
Source Code:
Explanation:
In the above program, first two line uses the prompt () to ask the user to input the value of the length and width of the rectangle and value stored in the variable's length and width.
The next line calculates the area and perimeter by using the above mention formula and stored in the variable's area and perimeter
Last two lines document.write() used to display the result on the page. In the first line, it displays the area and second line it displays the perimeter.
Output:
Final Words:
I hope you understood how to calculate the Area and perimeter of rectangles using javascript. In the next article, we are going to solve the same problem by using functions and buttons. If you have any suggestions, please feel me to write the comment box
No comments:
Post a Comment