[英]Making sum of two variable with extra text X=
Two variables A and B. I need to print sum of these two variables with extra word X= like,两个变量 A 和 B。我需要用额外的字 X= 打印这两个变量的总和,
input输入
A=3; A=3; B=2;
B=2;
output, X=5;输出,X=5;
I need (X=5;) this total answer with X= how can I do it in javascript??我需要 (X=5;) 这个带有 X= 的总答案我如何在 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在你的 html
<div id="sum"></div>
Template strings can be made with ` ` symbols.模板字符串可以用 ` ` 符号组成。 For example, let's say you have variable
let name = "bob";
例如,假设您有变量
let name = "bob";
. . You can make a template string out of it with
console.log(`Hello, ${name}`);
你可以用
console.log(`Hello, ${name}`);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.