Salman Tahir
Salman Tahir

Reputation: 7

How to produce output of two values in the form of an equation rather than just the output?

I'm working on a simple JavaScript program and i want the output in form of an equation e.g 2 x 2 = 4. i want such exact equation as the output. The code is below. any help?

<script>
function input() {
  value1 = 1 * prompt("1st number", 0);
  value2 = 1 * prompt("2nd number", 0);
  document.getElementById("v1").innerHTML = (value1)
  document.getElementById("v2").innerHTML = (value2)
}

function output() {
  document.getElementById("check").innerHTML = (value1 * value2);
}
</script>

Upvotes: 0

Views: 41

Answers (1)

Usman
Usman

Reputation: 463

Try this code.

function input() {
  value1 = 1 * prompt("1st number", 0);
  value2 = 1 * prompt("2nd number", 0);
  document.getElementById("v1").innerHTML = (value1)
  document.getElementById("v2").innerHTML = (value2)
  output()
}

function output() {
  document.getElementById("check").innerHTML = `${value1} * ${value2} = ${value1 * value2}`;
}

input();
<div id="v1"></div>
<div id="v2"></div>
<div id="check"></div>

Upvotes: 1

Related Questions