Giving me an error


#1

// Write your code below
const bobsFollowers = [‘Bryan’,‘Steph’,‘Mary’,‘Patrick’]
const tinasFollowers = [‘Yen’,‘Steph’,‘Mary’];
const mutualFollowers = [];

for (let i = 0; i < bobsFollowers.lenght; i++){
for(let n = 0; n < tinasFollowers.lenght; n++){
if (bobsFollowers[i] === tinasFollowers[n]){ mutualFollowers.push(bobsFollowers[i])
}
}
};

I don’t why is still giving me an error, can you help me?


FAQ: Loops - Nested Loops
#2

its .length not .lenght :wink:


#3

let bobsFollowers = [‘Joe’, ‘Marta’, ‘Sam’, ‘Erin’];
let tinasFollowers = [‘Sam’, ‘Marta’, ‘Elle’];
let mutualFollowers = ;

for (let i = 0; i < bobsFollowers.length; i++) {
for (let j = 0; j < tinasFollowers.length; j++) {
if (bobsFollowers[i] === tinasFollowers[j]) {
mutualFollowers.push(bobsFollowers[i]);
}
}
};

Hi!
I don’t understand this line of code " mutualFollowers.push(bobsFollowers[i]); " I know we must .push() the mutual followers from bob and tina, but why after declare .push(), we call again (bobsFollowers[i] ???


FAQ: Loops - Nested Loops
#4

Nested Loops

It’s arbitrary which one we push in since they are both the same value. What 's important is that we use the correct index. bobsFollowers[i] or tinasFollowers[j].