Area Calculator In Javascript

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.

area calculator
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

Area calculator result

I hope this code will helpful for you.