# Not working, please let me know why

**URL:** <https://forum.freecodecamp.org/t/not-working-please-let-me-know-why/448310>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [February 25, 2021, 4:08am UTC](https://forum.freecodecamp.org/t/not-working-please-let-me-know-why/448310 "2021-02-25T04:08:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![am93](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/am93/32/194443_2.png) [@am93](https://forum.freecodecamp.org/u/am93)\
**Post date:** [February 25, 2021, 4:08am UTC](https://forum.freecodecamp.org/t/not-working-please-let-me-know-why/448310/1 "2021-02-25T04:08:34Z")

</div>

Hi what is wrong with my code?

```
  **Your code so far**

```

```js

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:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [February 25, 2021, 4:44am UTC](https://forum.freecodecamp.org/t/not-working-please-let-me-know-why/448310/2 "2021-02-25T04:44:12Z")

</div>

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.

> [@am93](#):
>
> ```auto
> if (!arr2.includes(arr1[i]));
> //push arr1 to newArr
> newArr.push(arr1[i]);
> 
> ```

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

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

```

---

<div class="post-metadata">

**Author:** ![am93](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/am93/32/194443_2.png) [@am93](https://forum.freecodecamp.org/u/am93)\
**Post date:** [February 25, 2021, 5:48am UTC](https://forum.freecodecamp.org/t/not-working-please-let-me-know-why/448310/3 "2021-02-25T05:48:49Z")

</div>

Gotcha, I ended up using the filter method and did it that way 👍

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [August 26, 2021, 5:49pm UTC](https://forum.freecodecamp.org/t/not-working-please-let-me-know-why/448310/4 "2021-08-26T17:49:02Z")

</div>

Closed on August 26, 2021, 5:49pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
