Mi scervella su questo. Ho il codice qui sotto: le prime fasi di un gioco JavaScript. Tutti gli oggetti sono ben definiti e sto usando jQuery per l'interazione DOM. Il puzzle è creato con il seguente codice JS:Perché il ciclo for si interrompe dopo una ripetizione?
var mypuzzle = new puzzle("{solution:'5+6+89',equations:[['5+3=8',23,23],['5+1=6',150,23],['5+3=6',230,23]]}");
Tuttavia, l'anello nella parte inferiore del codice non andrà oltre la prima iterazione. Qualche idea del perché? Nessun errore viene generato.
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();
}
A cosa servono le "iterazioni"? – ChrisF
Dove è definito 'JSON.parse'? –
Cosa succede quando si esegue il debug di questo? – Charlie