In this blog post, we learn how to write a javascript function to calculate the area.
To find the area of this square, we just multiply the area.

A = x * y
A = 5 * 5
A = 25 square inch
So we will write a function in javascript that returns the multiple of two entered values.
Html
<h1>Area Calculator for Rectangles</h1>
<form>
Side Length One<br>
<input type="text" id="x_value"><br> Side Length Two<br>
<input type="text" id="y_value">
</form>
<button id="button">SUBMIT</button>
<p id="output"></p>
Javascript
var one, two;
var output = document.getElementById("output");
function calculate() {
x= document.getElementById("x_value").value; //Change1
y= document.getElementById("y_value").value; //Change1
output.innerHTML = x* y;
}
var button = document.getElementById("button");
button.onclick = calculate;
Result

I hope this code will helpful for you.

Brijpal Sharma is a web developer with a passion for writing tech tutorials. Learn JavaScript and other web development technology.