Javascript program to calculate the multiplication and division of two numbers

In this program, we are going to learn about how to multiply and divide two numbers using JavaScript, where the two numbers are entered by the user using a textbox.

Before reading this code you should know about.

  • HTML Input
  • HTML DOM
  • Javascript Function
  • HTML Button
  • HTML onclick event.

HTML Code

<!DOCTYPE HTML>
<HTML>

<body>
  <h3>Javascript program to calculate the multiplication and division of two numbers</h3>
  <div>
    Enter first number :<input type="text" id="Num1"><br />
    Enter Second number:<input type="text" id="Num2"><br />
    <button onclick="multiply()">Multiply</button>
    <button onclick="divide()">Divide</button>
    <p>The Multiplication and division of two numbers is :</p>
    <span id="result"></span>
  </div>
</body>

</HTML>

CSS Code

function multiply() {
  var a = parseInt(document.getElementById("Num1").value);
  var b = parseInt(document.getElementById("Num2").value);
  var c = a * b;
  document.getElementById("result").innerHTML = c;
  
}

function divide() {
  var a = parseInt(document.getElementById("Num1").value);
  var b = parseInt(document.getElementById("Num2").value);
  var c = a / b;
  document.getElementById("result").innerHTML = c;
  
}

When we hit multiply the output will look like this

avascript program to calculate the multiplication and division of two numbers

When we hit divide the output will look like this

avascript program to calculate the multiplication and division of two numbers
Facebook
Twitter
LinkedIn
Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

ABOUT ME !!
Johan William

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

RECENT POSTS

TEST