JS: why wont my code work if i change name?

Hi guys,
I am trying to learn JS by copying the code from FCC and putting it into Repl.it and tweaking it for my own testing and understanding. I am now struggling with this code and dont understand why changing “propName” to something like “motor” or “crocName” returns “undefined”. How can changing this property name make a difference when “propName” isnt even used anywhere else in the code?:

var someObj = {
  propName: "John"
};
function propPrefix(str) {
  var s = "prop";
  return s + str;
}
var someProp = propPrefix("Name");
console.log(someObj[someProp]);

"propName" is used.

var someProp = propPrefix("Name"); // someProp is now equal to "propName"
console.log(someObj[someProp]); // the same as saying console.log(someObj.propName)

sorry I dont understand. How is propName = “Name”?

It isn’t.
someProp is equal to "propName" because it that is the value returned by propPrefix("Name").

Okay…so say you wanted to tweak this code and just change all the variable names to car properties such as “car” “engine” “wheels” “colour” etc, how would you change them all?
Sorry, i really struggle with variable names given in FCC and they just confuse me, so I need to change them to something I understand. Thanks

var car = {
  engine: "V6",
  wheels: 4,
  doors, 2,
  colour: "red"
};

This exercise is built on the assumption that there is a standard naming convention for property names: that they are all “prop” followed by a descriptive word.

So if you had

var someCar = {
    propWheels: 4,
    propGas: "Diesel"
}

Then you might do something like

var wheelsCount = someCar[propPrefix("Wheels")];
console.log("The car has "+ wheelsCount + " wheels.");

hmm… this is somewhat making sense. I am assuming the (str) means the parameter will be a string. is that right?

str is just the name given to the parameter. By convention, it indicates that it is a string. If you were to pass in a number, it would still work because that number would be implicitly cast as a string when you do s + str.

I see. Thanks for the explanation. Its making sense now! Much appreciated!

I’m glad I could help. Happy coding!