I am trying to understand the code in question. what I don’t understand is on line 8 and 9
8. var someProp = propPrefix(“Name”); // someProp now holds the value ‘propName’
9. console.log(someObj[someProp]); // “John”
from my understanding is when we call a function with “” it means it is argument that get replace by parameter so this should print sName
and on line 9, it will reuntn someObj[sName] which won’t be found?
Even positing question confuses me.
1. var someObj = {
2. propName: "John"
3. };
4. function propPrefix(str) {
5. var s = "prop";
6. return s + str;
7. }
8. var someProp = propPrefix("Name"); // someProp now holds the value 'propName'
9. console.log(someObj[someProp]); // "John"
Your code so far
// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line
var playerNumber; // Change this line
var player = testObj; // Change this line
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36
.
Challenge: Accessing Object Properties with Variables
Link to the challenge: