我正在尝试将数字输入传递给函数并获得答案。这是我到目前为止所拥有的。
var x = firstProblem();
function firstProblem(firstNumber, secondNumber) {
return firstNumber * secondNumber;
}
document.getElementById("first").innerHTML = x;
#firstNumber {
height: 3em;
font-size: 2em;
}
#secondNumber {
height: 3em;
font-size: 2em;
}
<p>If I save <input type="number" id="firstNumber" value="0"> a week how many weeks would It take to get to <input type="number" id="secondNumber" value="0"></p>
<p id="first"></p>
答案 0 :(得分:0)
const first = document.getElementById('first');
const firstNumber = document.getElementById('firstNumber');
const secondNumber = document.getElementById('secondNumber');
firstNumber.addEventListener('change', onChange);
secondNumber.addEventListener('change', onChange);
function onChange() {
first.innerHTML = firstProblem(firstNumber.value, secondNumber.value);
}
function firstProblem(firstNumber, secondNumber) {
return firstNumber * secondNumber;
}