Hello, first, here we are creating a RPG, they make us create a variable using “locations” with 2 objects inside it as follows:
const locations = [
{
name: "town square",
"button text": ["Go to store", "Go to cave", "Fight dragon"],
"button functions": [goStore, goCave, fightDragon],
text: "You are in the town square. You see a sign that says \"Store\"."
},
{
name: "store",
"button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"],
"button functions": [buyHealth, buyWeapon, goTown],
text: "You enter the store."
},
];
As you can see we also create a function to update said locations, as follows:
function update(location) {
button1.innerText = location["button text"][0];
button2.innerText = location["button text"][1];
button3.innerText = location["button text"][2];
button1.onclick = location["button functions"][0];
button2.onclick = location["button functions"][1];
button3.onclick = location["button functions"][2];
text.innerText = location.text;
}
and this works fine. BUT my question is, WHY does the function use parameter “location”, as in "function update(location)", instead of the variable we created that is “locationS” as in “const locations”. I don’t understand this because what is telling the function to get the info from the objects we have in the variable “locations” if we’re telling the function to look for them in something called “location”, shouldn’t they be the same? as in: “const locations” and “function update(locations)”?
obviusly for some reason not, because as soon as I change it the code stops working I just started JS today and I just want to make sure I understand what I’m doing before I move on.