Array Positions

I need help with this lesson, I dont know where to start at, please help me out!

Could you provide a little more information on what exercise your looking and what error message you get and maybe what your code looks like?

I am working on Introduction to ‘For’ Loops in JS on number 10 Array positions.
This is my code and error:

var junkData = [“Eddie Murphy”, 49, “peanuts”, 31];
TypeError: console.log is not a function
Oops, try again.

Well good that you posted it because your problem has nothing to do with array positions. This: junkData[3] would have been suitable to get the 4th element in the junkData array. The problem is this line:


where you assigned, well undefined, to console.log. Meaning that in the progress console.log will be undefined instead of this neat function that prints stuff to the screen. So to fix this get rid of the line altogether and then refresh the page, that should reload the javaScript and thereby reset the initial value of console.log.

1 Like

I refresh the page and it isn’t working it says I should’ve printed out 31 as this is the 4th element

Here is my code

// Practice array!
var junkData = [“Eddie Murphy”, 49, “peanuts”, 31];
console.log = junkData[3];

Can you please change your avatar? We look identical and i dont want people confusing you over me… Thankyou

I was having trouble with this part as well, and it accepted my code finally which is:

var junkData = [“Eddie Murphy”, 49, “peanuts”, 31]; {
I am not 100% on why it worked, but i’ve been on all day so I might be burnt out lol.


Hope this help.
I think this line is your problem


it should be


PS. Read very carefully the Instruction. the instruction says: express what the fourth element in the array is.

var junkData = [“Eddie Murphy”, 49, “peanuts”, 31]

is equals to:

var junkData = [0, 1, 2, 3]

Meaning:[0] is the first element in an array. [1] is the second, and so on…
Array indexes start with 0.

Here’s the whole code if you are still confused.

 var junkData = ["Eddie Murphy", 49, "peanuts", 31];

The output will be 31.


Yup gracie017 you are correct. However be sure to refresh your page and re-submit the code.

Final code should be:

var junkData = ["Eddie Murphy", 49, "peanuts", 31]; console.log(junkData[3]);

Thanks for the help.

Yup gracie017 you are correct.

thx man it helped:slight_smile: