Why does this program keep crashing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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"));

28th Nov 2016, 10:05 PM
Ben
Ben - avatar
1 Answer
+ 2
at the for loop for array you wrote x< instead of y< it is y<ops.length unlike x<msg.
29th Nov 2016, 7:07 AM
Sandeep Chatterjee