Iteration Challenege

Tell us what’s happening:
I can’t come up with a solution for this challenge. The hints all suggest some sort of iteration moving through the counting of the arr, but I don’t understand how that helps. I don’t even know what the arrays are and what the elements could be. I suppose that’s not important, but I am unable to solve this one.

  **Your code so far**

function filteredArray(arr, elem) {
let newArr = [];
// Only change code below this line
for (let arr = elem){
if(arr[elem].indexOf(elem))
}
// Only change code above this line
return newArr;
}

console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36

Challenge: Iterate Through All an Array’s Items Using For Loops

Link to the challenge:

what do you want to do with this loop? aren’t you getting a syntax error?
what kind of loop do you want there?

you need the correct logic flow, but you also need the correct syntax, without correct syntax nothing works, the errors stop everything from executing

#Spoiler I am trying to solve this challenge. I don’t know what I want to do with this loop beyond sort through the array function and weed out the elements that may be in it to return a new array without any elements. The code above was me trying anything to make it happen.


This is what was suggested to work, but it keeps telling me i is not defined. I have very little knowledge of this so I am unable to speak to you intelligently about this. Thank you. /Spoiler

Try indenting your code and you should see why you are at least getting the ReferenceError shown above.

You have 3 keywords to declare a variable in JavaScript: let, const, var.

let and const have the same scope which is block scope an this means if you declare a variable with them that variable is only defined within the scope of the block, and anytime you wrap something in curly brackets {} it is inside its own block, and for loops are a block.

1 Like

can you post your code instead of posting a screenshot? it’s always better when you ask for help

Definitely. I will do that moving forward. Thank you