-2
當您運行在控制檯這段代碼,它工作正常,但不能以這種方式工作 - http://jsbin.com/raguquka/1/出了什麼問題javascript代碼
這適用於控制檯 -
function solveEquation() {
// format ax+by=c
var eq1 = "3x+5y=4", // equation 1
eq2 = "5x+6y=2", // equation 2
// separate ax, by & c
eq1Parts = eq1.split(/[\+\-\=]/),
eq2Parts = eq2.split(/[\+\-\=]/),
// get the value of a, b & c
a1 = parseInt(eq1Parts[0]),
b1 = parseInt(eq1Parts[1]),
c1 = parseInt(eq1Parts[2]),
a2 = parseInt(eq2Parts[0]),
b2 = parseInt(eq2Parts[1]),
c2 = parseInt(eq2Parts[2]),
// substitution and elimination
// https://www.khanacademy.org/math/algebra/systems-of-eq-and-ineq/fast-systems-of-equations/e/systems_of_equations
B1 = b1 * a2,
C1 = c1 * a2,
B2 = b2 * a1,
C2 = c2 * a1,
// A1 and A2 cancels out, no need to specify them
// unknowns
y = (C1 - C2)/(B1 - B2),
x = (c1 - b1 * y)/a1; // putting the value of y in equation 1
ansContainer.textContent = "x = " + x + ", y = " + y;
}
我知道這是一個bug的代碼,這是非常早期的階段,我卡住了。
ansContainer.textContent沒有定義 – Tarek
'ansContainer =的document.getElementById( 「ANS-容器」)' – user3317779
控制檯告訴你的一切,看它的錯誤消息。 – epascarello