var o = [1, 7, 8, 12, 17, 21, 28, 32, 35, 47]; var z = []; var k = []; function abc() { for (var i = 0; i < o.length; i++) { if (o[i] % 2 == 0) { z = o[i]; console.log(z); } else if (o[i] % 2 == 1) { k = o[i]; console.log(k); } }; }; console.log(z); Closed due to the fact that off-topic participants are Visman , aleksandr barakin , Kromster , pavel , Grundy 15 May '17 at 6:35 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - aleksandr barakin, Kromster, pavel, Grundy
- var o = [1, 7, 8, 12, 17, 21, 28, 32, 35, 47]; var z = []; var k = []; function abc () {for (var i = 0; i <o.length; i ++) {if (o [i]% 2 == 0) {z = o [i]; console.log (z); } else if (o [i]% 2 == 1) {k = o [i]; console.log (k); }}; }; console.log (z); - Programmer
- again ... again you need to ask "what's wrong with him"? and add a question by clicking "edit", but do not paste the code in the comments - Alexey Shimansky
- why do you think something is wrong? - Grundy
- Code Does Not Work - Programmer
- oneQuestions asking for help with debugging (“why does this code not work?”) Should include the desired behavior, specific problem or error ..... the code does not work - the concept is very vague and incomprehensible absolutely - Alexey Shimansky
|
1 answer
I sense two problems here:
you need to push to bring the result of the operation into arrays. Those. need to write like this:
z.push(o[i]);and
k.push(o[i]);you don't call the
abc()function itself so that everything starts working
var o = [1, 7, 8, 12, 17, 21, 28, 32, 35, 47]; var z = []; var k = []; function abc() { for (var i = 0; i < o.length; i++) { if (o[i] % 2 == 0) { z.push(o[i]); //console.log(z); } else if (o[i] % 2 == 1) { k.push(o[i]); //console.log(k); } }; }; abc(); console.log(z); console.log(k); - call abc () is it necessary? - Programmer
- @Programmer of course. so that the mechanism inside the function is set in motion, you need to call it. I'm just wondering: how do you think, why do they exist and what role do they perform and why did you write the code inside it? - Alexey Shimansky
- okay understandable))) - Programmer
|