Help with Java Script Section 6 Loops Nested Loops,

Hi,

I am logging this code from Question 6 to the Console, and its returning Numbers. Should it be returning Numbers or Names? Thanks… How do I get it the loop to return Names from the Array?

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]) {
console.log(mutualFollowers.push(bobsFollowers[i]));

}

}
};

I’m not certain what the lesson wants you to log, though I would guess it wants the names. Could you post a link to the lesson?

Not super important but to return something is referring to a function sending a value back to were the function was called. Here you are just logging to the console with console.log().

Currently you are getting a number because you are logging the result of using .push() on an array which return the new length of the array.

If you want to log the names there are several different ways you could do this. One would be to log each value from mutualFollowers after the for loops. Or, if you wanted to log it inside the for loop, you could place a console.log() after you push to the array, logging the same element from bobsFollowers.

1 Like