Formatting for loops and variable declarations

When I run this in a separate compiler (Atom: Script) I get the correct value ([ ‘Emily’, ‘Matt’ ]) but for some reason I am getting the incorrect return in this environment. Another question I had is in regards to variable declaration, please notice my commented out line 6, is it best practice to always use inline declaration in js or can I clean my code by declaring variables like this and then assigning their values in line later? Thank you for your help and attention.

// Write your code below
const bobsFollowers = ['John','Jane','Emily','Matt'];
const tinasFollowers = ['Emily','Tony','Matt'];
let mutualFollowers = [];

//let i, j;
//will iterate thru 4 times then stop b/c 4 !< 5
for(let i = 0; i < bobsFollowers.length; i++){
  //iterates thru 3 times then jumps out to other loop to iterate and repeat
  for(let j = 0; j < tinasFollowers.length; j++){
    if(bobsFollowers[i] === tinasFollowers[j]){
      mutualFollowers.push(bobsFollowers[j]);
    }
  }
};
console.log(mutualFollowers);
//output: [ 'John', 'Emily' ]

To conform to normally recognized standards you should use the code as you have written ie.

for(let i = 0; i < bobsFollowers.length; i++)

You could use:

let i, j;
for(i=0; i < bobsFollowers.length; i++)

But it’s kinda unconventional. In the end, it’s your code, and you can do what you prefer. As long as you’re consistent, you and others will be able to decipher your code. If you’re looking to get hired as a developer, you’ll probably be required to follow established standards, so in my opinion, I would conform. Hope this helps!

1 Like

Thanks for your help I’ll start to use inline declarations, as for the code fix I somehow have it typed up correctly in my other compiler but not in CodeAcademy’s lol thanks again for the assist.