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];
console.log=junkData[31];
console.log(junkData[3]);
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:
console.log=junkData[31];
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.
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]; {
junkData[index];
console.log=junkData=undefined;
}
I am not 100% on why it worked, but iâve been on codecademy.com all day so I might be burnt out lol.
Hope this help.
I think this line is your problem
junkData[index];
console.log=junkData=undefined;
it should be
console.log(junkData[3]);
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];
console.log(junkData[3]);
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: