0
// YOUR CODE
function evenAndOdd(array){
    let newarray =[[],[]]
    for(let i=0; i<array.length; i++){
        if(array[i]%2===0){
            newarray[0].push(array[i])
        }
        else{
            newarray[1].push(array[i])
        }
    }
    return newarray
}
console.log(evenAndOdd(1,2,3,4,5,6))
// DO NOT EDIT BELOW

module.exports = evenAndOdd;

How do I fix this?

Im a beginner currently learning to code in javascript and am not sure how to fix this. Please try to use the same terms I've used here as I've not covered everything. How do I use an array as an argument in a function? I tried doing let array=[] and also evenAndOdd([]) but that doesnt work. And have I coded the part to put the even numbers in one array and the odd numbers in the other correctly. This is the question that I'm trying to answer:

Define a function, evenAndOdd, that accepts an array.

evenAndOdd should return a new array containing two smaller arrays:

The first element in the new array should be an array with all of the even numbers from the original array.

The second element in the new array should be an array with all of the odd numbers from the original array.

  • Your code works given your problem *description*. The example input call in your question uses an incompatible format with the description though - to make that work, you'll need rest syntax. – CertainPerformance Nov 30 '22 at 02:01
  • Perhaps you meant `console.log(evenAndOdd([1,2,3,4,5,6]))`? – Spectric Nov 30 '22 at 02:06
  • when I press run, I'm given the answer [[][]]. Im not sure what is going on here. – Hamza S Nov 30 '22 at 02:27
  • is rest syntax ...array? Ive just done used that and it worked. But unfortunately it doesnt give me marks because I need to answer it a different way. Since I havent covered rest syntax it expects me to do this questions some other way. – Hamza S Nov 30 '22 at 02:47

0 Answers0