我正在开发一个简单的JavaScript程序,我希望输出以方程式形式出现,例如2 x 2 =4。我希望有这样的精确方程式作为输出。代码如下。有帮助吗?
<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>
答案 0 :(得分:1)
尝试此代码。
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>