Tell us what’s happening:
In the explanation, it uses two examples the second one is really difficult for me to understand how it’s doing the same thing as the first example in the challenge…
How does the “Name” portion of propPrefix(“Name”) end up being “John” if “Name” is not defined?
The 2nd example below
Another way you can use this concept is when the property’s name is collected dynamically during the program execution, as follows:
var someObj = {
propName: "John"
};
function propPrefix(str) {
var s = "prop";
return s + str;
}
var someProp = propPrefix("Name"); // someProp now holds the value 'propName'
console.log(someObj[someProp]); // "John"
how is the code output not " propJohn " or “Johnprop” if it says return s + str
and s = "prop"
below does s+ str
not equal propJohn?
function propPrefix(str)
var s = "prop";
return s + str;
if it says
console.log(someObj[someProp]);
not sure if I didnt pay attention on some of the lessons before but this section is a complete curve ball
my flawed logic leads me to believe
someObj = " John "
=== John
&
someProp = propPrefix("Name");
=== propJohn"Name"
can ‘someProp’ , ‘propName:’, ‘propPrefix’ be changed to any other word || is prop short for property?
If I change the code like below is it still valid? //example below
var dogs = {
Fido: "Mutt"
};
function dogName(str){
var s = "Dog"
return s + str;
}
var someDog = dogName("Name"); //someDog now holds the value ?
console.log(dogs[someDog]);
honestly most of the time FCC shows me 2 ways to do the same thing it’s usually too much to process, another example where this happened was with the counting cards challenge had 2 answers. The syntax of the second one looked like hieroglyphs at first, thankfully going back, and looking at it later it makes more sense. Although at the time of the challenge it just made it more intimidating to learn/continue… because I assumed I wasnt understanding the material as I should
// Only change code below this line
var regex = /[JQKA]/;
if (card > 1 && card < 7) {
count++;
} else if (card === 10 || String(card).match(regex)) {
count--;
}
if (count > 0) return count + " Bet";
return count + " Hold";
// Only change code above this line
}
Your code so far
// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line
var playerNumber = 16; // Change this line
var player = testObj[playerNumber]; // Change this line
Challenge: Accessing Object Properties with Variables
Link to the challenge: