Mein Gehirn auf diesem ein. Ich habe den folgenden Code: die ersten Schritte eines JavaScript-Spiels. Alle Objekte sind gut definiert und ich verwende jQuery für die DOM-Interaktion. Das Puzzle wird mit dem folgenden JS-Code erstellt:Warum stoppt meine for-Schleife nach einer Iteration?
var mypuzzle = new puzzle("{solution:'5+6+89',equations:[['5+3=8',23,23],['5+1=6',150,23],['5+3=6',230,23]]}");
jedoch die Schleife am unteren Rande des Codes wird nicht weiter gehen als die erste Iteration. Irgendeine Idee warum? Es werden überhaupt keine Fehler ausgelöst.
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();
}
Was ist "Iterationen" eingestellt? – ChrisF
Wo ist 'JSON.parse' definiert? –
Was passiert, wenn Sie dies debuggen? – Charlie