Accessing Objects Properties with Variables - Bracket notation

Accessing Objects Properties with Variables - Bracket notation
0

#1

I’m going to begin this post with a cautionary warning: I’m annoyed with this exercise and I might come across a little whiny about it, so please forgive me.

I did search the forum already, but I did not see anything specific to this particular problem I’m having at the moment.

The instructions are telling me to do ONE thing: “Use the playerNumber variable to lookup player 16 in testObj using bracket notation.”

But if you look at the code area, you can immediately see a little problem; there are clearly two things that must be done.

So, if I follow the instructions, and change the first variable, I get the green checkmark for that line. But I have no idea what to do to the second line, and the instructions do not even acknowledge its existence.

The instructions are extremely vague. Extremely. Vague.

I think I get it though. This is to get us ready for real life, right? This is exactly how real customers give you software requirements, isn’t it! Yes I do remember now.

Sorry my bad.

But if anyone cares to elaborate on this exercise, I would really really be grateful. Because I still don’t know what to do here.

Thanks


#2

It is one task, but you will need to change 2 lines for it.

  1. Set playerNumber to the player number you want to search for (player 16)
  2. Access this player from testObj with bracket notation (e.g.: testObj["19"] returns the value that matches with the given key (“19”), so it returns “Unitas”.

#3

I still can’t get this to work.

(I’ve been doing other stuff today, not just this!!)

The playerNumber part works fine. playerNumber = testObj[16];

However,

The player = testObj; line I have tried the following:
brackets [16]
brackets and quotes [“16”]
brackets [Montana]
brackets and quotes [“Montana”]
brackets [playerNumber]
etc.

At best I have achieved 2 green checks out of 5. :cry:


#4

So what value does it have?


#5

The test returns the value:

Montana


#6

Yes, and it should be a number. So you are doing the task in one operation, but they expect you to use 2 lines of code.

So, playerNumber should just be the player number and not a string value. You can then use bracket notation (and playerNumber) to get the value you want: Montana.


#7

I don’t understand. This is probably supposed to be easy. We should be using what we already learned in the previous couple of exercises, right? Those were super easy to understand, the instructions were clear and everything. I don’t know why this exercise is not making any god damn sense to me.

I tried adding a third variable above the other two, like
var favorite = “Montana”;

Because the example they provided sorta looked like that, but…
Nope.


#8

Use the playerNumber variable to lookup player 16 in testObj using bracket notation.

The first test says: "playerNumber should be a number", so:
var playerNumber = 16;

You can then use playerNumber:
var player = testObj[playerNumber];


#9

::speechless::

well the forum police won’t let me get away with that, and, also, I sincerely do appreciate your kindness and I apologize for the lump on your head where you must have been banging it on the desk.

But I still insist those instructions were SUPER DUPER not at all close to saying that!


#10

FWIW i completely agree that the instructions were incredibly vague and did not take me in that direction either.


#11

Thanks for the help, now get it!


#12

Totally agree… This was so confusing and really counter-intuitive based on the previous two problems…


#13

I just finished the exercise. I do agree the instructions could have been a little more clear