+ 2
Why does this program keep crashing?
function chkOp(c) { ops = ['+','-','*','/']; for (var y = 0;x<ops.length;y++) { if (c == ops[y]) { return true; } } return false; } function wrapList(msg) { var list = []; for (var x=0;x<msg.length;x++) { if (x == 0) { list[x] = msg[x]; } else if (!(chkOp(msg[x]) && !(chkOp(msg[x-1]))) { list[x-1] += "" + msg[x]; // 6+6 = 66 instead of 12 (by adding quote) } } return list; } document.write(wrapList("65+22"));
1 Answer
+ 2
at the for loop for array you wrote x< instead of y<
it is y<ops.length unlike x<msg.