10.Array Positions


#1

Hey again people! I would like to ask you a favour)Can you show me what 
to write in exercise "10.Array Positions".I can't understand the task!


/ Practice array!

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

It's that exercise!


#2

Help me please :relaxed:


#3

Please read the instructions to get an idea of what you're meant to do and what tools are available for you to carry it out. Right now you're just asking to have the exercise done for you and that's not worth yours or anyone else's time.

Ask specific questions that give you information that you need to do it yourself. If you're completely lost then it sounds like you you've rushed through previous exercises too fast and should double back and make sure you've understood what's taught. Running through content without learning anything and then asking others to solve things for you will not float your boat. It only puts you further behind.

The goal is by no means to pass exercises. The goal is to learn what they teach.


#4

Thank you very much.I guessed the answer.I know.Thanks)


#5

so, for me i'm on array positions.
var junkData=["Eddie Murphy",49,"peanut",31]
I put console.log=junkData[3]
it prints out 31 but when i submit it the response it
"oops,try again. Alas, you should have printed out 31, as that is the 4th element"
Did I break the code? reset it and did it again multiple times but it gives me the same response.


#6

I'm getting the same error!

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

this DOES print out 31... but the error message is telling me it's not. I've tried it without the () around the var... adding [] instead. I just don't know what's wrong with it.


#7

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


#8

@anthonycalvillo + @designwhiz17355 Well what does a statement A = B do in programing? It assigns the value of B to the variable A and that is exactly what you're doing here:

console.log = (junkData[3]);

You assign the value of junkData[3] which is 31 to console.log and by doing so you overwrite what was originally in console.log. So you neither use console.log nor is console.log usable anymore after this statement is executed, because 31 does not have a property that prints stuff to the console :slight_smile:

Side note: The reason why you still see a 31 in the console is because the console is always responds to your input by echoing the last value of your code (except when there is none aka undefined) so as A = 31 has a value of 31 you see the 31 but that goes through a different channel than console.log(31). Which you can see by just typing "test" in a blank editor window and pressing submit and comparing this to console.log("test"). The first echoes it including the "" and the console.log doesn't.

Now to fix it you need to get rid of the = sign

console.log = (junkData[3]); //wrong
console.log(junkData[3])   ; //correct

which means that you're no longer reassigning the console.log variable but instead using the function. But so far this will only tell you that console.log aka 31 is not a function, so to make this work you need to refresh the page to reset it to it's original value.

@bigboyee
That is kind of cheating :wink:
Unless you did not do it on purpose:

junkData[3];

this is the value you're looking for which is never used in your code again. And this console.log(31);, namely the 31, is by coincidence the value it has. So better print the 4th entry of the array instead of reading what the 4th entry is and then printing it.


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.