For loop

i have write this code but i don’t have any result in the output, help me please

// Write your code below
let bobsFollowers = [‘john’, ‘anastacia’, ‘maria’, ‘fred’];
let tinasFollowers = [‘laura’,‘anastacia’, ‘john’];
let mutualFollowers = ;
for (let i = 0; i < bobsFollowers; i++) {
for (let j = 0; j < tinasFollowers; j++) {
if (bobsFollowers[i] === tinasFollowers[j]) {
mutualFollowers.push(bobsFollowers[i]) ;
console.log(mutualFollowers);

}

}

}

Hey there,

Your for loops aren’t running because they evaluate to false. They should, in fact, evaluate to true.

If you try this:

let bobsFollowers = ['john', 'anastacia', 'maria', 'fred'];
let tinasFollowers = ['laura', 'anastacia', 'john'];
let mutualFollowers = [];

let i = 0;
console.log(i < bobsFollowers);

It will output false.

That’s because you’re attempting to compare a number against an array (precisely, checking if a number is smaller than an array). This won’t work.

However, if you were to compare a number against the length of an array (which would also result in a number), then the output would be true and your loops would run.

1 Like