Not working, please let me know why

Hi what is wrong with my code?

  **Your code so far**

function diffArray(arr1, arr2) {
// store items that are not repeated
var newArr = []; 
// loop through arr1
for (let i = 0; i < arr1.length; i++) {
// if arr2 doesn't innclude arr1[i]
  if (!arr2.includes(arr1[i]));
//push arr1 to newArr
  newArr.push(arr1[i]);
}
return newArr;
} 

console.log(diffArray(["diorite", "andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"])); 
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36.

Challenge: Diff Two Arrays

Link to the challenge:

Hi again!

Two things.

Right now you are only checking if arr2 does not include elements from arr1.
But you should check the opposite as well.

Also, there is an issue here with the if statements.

You should put something in that if statement instead of just ending it with a semicolon and then pushing items to the array.

 if (!arr2.includes(arr1[i])){
//do something here
}
2 Likes

Gotcha, I ended up using the filter method and did it that way :+1: