justCoolStuff()

The output is correct, but I couldn’t pass the test and suggestion?

// Write your code here:
const justCoolStuff =(arr1,arr2)=>{
  for(let i = 0; i < arr1.length; i++){
    for(let j =0; j < arr2.length; j++){
      if(arr1[i] == arr2[j]){
        console.log(arr1[i]);
       //return arr1.filter(el => el);
      

      }

    }

  }

}

// Feel free to uncomment the code below to test your function

const coolStuff = ['gameboys', 'skateboards', 'backwards hats', 'fruit-by-the-foot', 'pogs', 'my room', 'temporary tattoos'];

const myStuff = [ 'rules', 'fruit-by-the-foot', 'wedgies', 'sweaters', 'skateboards', 'family-night', 'my room', 'braces', 'the information superhighway']; 

console.log(justCoolStuff(myStuff, coolStuff))
// Should print [ 'fruit-by-the-foot', 'skateboards', 'my room' ]


1 Like

Could you post a link to the exercise please so I can see what should be the code?
Without the link, I think that the exercise wants you to return an array containing the duplicates, so they can test your function.
So the correct code should be:

const justCoolStuff =(arr1,arr2)=>{
  let arr = [];
  for(let i = 0; i < arr1.length; i++){
    for(let j =0; j < arr2.length; j++){
      if(arr1[i] == arr2[j]){
        arr.push(arr1[i]);
      }
    }
  }
  return arr;
}

const coolStuff = ['gameboys', 'skateboards', 'backwards hats', 'fruit-by-the-foot', 'pogs', 'my room', 'temporary tattoos'];

const myStuff = [ 'rules', 'fruit-by-the-foot', 'wedgies', 'sweaters', 'skateboards', 'family-night', 'my room', 'braces', 'the information superhighway']; 

console.log(justCoolStuff(myStuff, coolStuff))

But I’m not sure without the link to the exercise.
Oh and just one small thing, I’d recommend using === to check if two values are equal, since it also checks if the two values are the same type:

let boolean = true;
let string = "true";
let integer = 1;
boolean == string // true, since true is true BUT that's only true because as I said it doesn't check if they're the same type
boolean == integer // true, because 1 actually means true or on like in binary
boolean === string // false
boolean === integer // false

Intermediate JavaScript - justCoolStuff()

1 Like