-1

Two variables A and B. I need to print sum of these two variables with extra word X= like,

input

A=3; B=2;

output, X=5;

I need (X=5;) this total answer with X= how can I do it in javascript?? please help me.

Shivam
  • 1,345
  • 7
  • 28

2 Answers2

0

This should do it.

  function printSum(a, b) {
    return "X = " + (a + b);
  }

  var a = 2;
  var b = 5;
  var output = document.querySelector("#sum");
  var sum = printSum(a, b);

  output.textContent = sum;
  console.log(sum);

In your html

<div id="sum"></div>
Vladimir Mujakovic
  • 650
  • 1
  • 7
  • 21
0

Template strings can be made with ` ` symbols. For example, let's say you have variable let name = "bob";. You can make a template string out of it with console.log(`Hello, ${name}`);

tenderporkk
  • 45
  • 1
  • 6