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.
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.
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>
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}`);