Those are good questions that I don’t know. This is coming from this part of the course in this link here:
It says:
someProp would have a value of the string propName , and the string John would be displayed in the console.
Note that we do not use quotes around the variable name when using it to access the property because we are using the value of the variable, not the name .
const someObj = {
propName: "John"
};
function propPrefix(str) {
const s = "prop";
return s + str;
}
const someProp = propPrefix("Name");
console.log(someObj[someProp]);
They are trying to access a property from the object, but I see no link between the rest of the code and the someObj above it. propName and “John” is not showing in the rest of the code below of it.
someProp is supposed to have the value of “John” coming from the object, going through the propPrefix function.
I don’t see how the propPrefix funtion is tapping into the someObj.
I did the test on this section and it was simple, but this last example I am not connecting the dots… I am thinking they are replacing the actual working elements with the examples of str, “prop”, and “Name” to make it clearer, but I am just not getting it.
I understand how this works, no need to explain to me
You keep ignoring my question. What is the value of someProp? You won’t understand how this all fits together until you know that. I gave you a link to a previous challenge that explains how functions work. Do you understand how functions work? If so then you should hopefully be able to tell me what the value of someProp is.
I don’t think we can go any further until you get the value of someProp.
Given that the test, and the previous sample right above this sample are way easier… I am just going to qualify this sample as a bad sample.
I am speculating that the keywords of str, “prop”, and “Name” are not actually connected to a functional code, but that they are using it as sample of what would go there, rather than including an actual value of what would go there to make the code work.
This makes no sense. Look at the code in the function propPrefix. What does it return if you pass in the value “Name”. That’s what the value of someProp will be and then you will see how this all fits together.
Yes, its getting clearer, but I am not trying too hard.
It is a non working sample with the words changed to make a sample, but the sample doesn’t make much sense because they are not using the proper words to make it work.
Why don’t they just use “propName” instead of “someProp”? Or whatever else they are not using?