私の頭脳をこの上に置きます。私は以下のコードを持っています:JavaScriptゲームの最初の段階。すべてのオブジェクトは明確に定義されており、DOMインタラクションのためにjQueryを使用しています。パズルは、以下のJSコードを使用して作成されますforループが1回の繰り返しの後に停止するのはなぜですか?
var mypuzzle = new puzzle("{solution:'5+6+89',equations:[['5+3=8',23,23],['5+1=6',150,23],['5+3=6',230,23]]}");
しかし、コードの下部にあるループは、最初の反復よりもさらに行くことはありません。どんな考え?エラーは全くスローされません。
あなたがその名前のグローバル変数、およびあなたは「すべてのコードに書いたすべてのループを使用しているので、おそらくあなたのスコープに失敗あなたのカウンタ変数が(あなたがそれの習慣を作る場合は特に、それをやっているfunction equationBox(equation, top, left) {//draggable equation box
this.reposition = function() {
this.top = 0;
this.left = 0;
}
this.top = 0;//make random
this.left = 0;//make random
this.equation = equation;
if(top && left) {
this.top = top;
this.left = left;
}
this.content = this.equation.LHS.string + '<span> = </span>' + this.equation.RHS.string;
this.DOM = $('<li>').html(this.content);
}
function puzzle(json) {
this.addEquationBox = function(equationBox) {
$('#puzzle #equations').append(equationBox.DOM);
}
this.init = function() {
//this.drawPuzzleBox();
this.json = JSON.parse(json);
this.solution = new expression(this.json.solution || '');
this.equations = this.json.equations || [];
var iterations = this.equations.length;
for(i=0;i<iterations;i++)
{
console.log(i);
this.addEquationBox(new equationBox(stringToEquation(this.equations[i][0]),this.equations[i][1], this.equations[i][2]));
}
}
this.init();
}
"反復"とは何ですか? – ChrisF
'JSON.parse'はどこに定義されていますか? –
これをデバッグするとどうなりますか? – Charlie