So I am getting an array from php using ajax. In ajax, I want to break down the array to put certain parts into certain divs.
I made code here which selects which parts fit where and put them there:
while (array[x] != null) {
y = 0;
if (2 < x) {
if (x == 3) {
x = 0;
y = x;
} else {
y = x / 2
}
}
setTimeout(function() {
if (y == 0 || x % 3 === 0) {
var namestring = array[y];
var namestring = array[y].replace('[', '');
var namestring = namestring.replace('[', '');
var namestring = namestring.replace('"', '');
var namestring = namestring.replace('"', '');
}
if (y % 2 != 0 || y % 3 != 0 && x > 0) {
alert(y);
var date = array[y]
var date = date.replace('"', '');
var date = date.replace('"', '');
}
if (x % 2 == 0 && x > 0) {
var text = array[y];
var text = text.replace('"', '');
var text = text.replace('"', '');
var text = text.replace("]", '');
var text = text.replace("]", '');
createcard(namestring, date, text);
}
}, 500);
if (x > 500) {
break;
};
x = x + 1;
}
The problem is that this part:
if(2 < x) {
if (x == 3) {
x = 0;
y = x;
} else {
y = x/2
}
}
causes the program to crash. If I do not have it, then it works fine. Also, if I do not have this then my problem doesn't work. Why is this happening?
Thanks!