Where is the repetition they mention? - Role Playing Game - Step 46

I don’t need help answering the question, but the question says ,

“You have repetition in the goTown and goStore functions,”

and I am trying to understand what they are talking about. Where is the repetition? (I only pasted in the pertinent parts of the code because it was long.)

Your code so far

///

function goTown() {
button1.innerText = “Go to store”;
button2.innerText = “Go to cave”;
button3.innerText = “Fight dragon”;
button1.onclick = goStore;
button2.onclick = goCave;
button3.onclick = fightDragon;
text.innerText = “You are in the town square. You see a sign that says "Store".”;
}

function goStore() {
button1.innerText = “Buy 10 health (10 gold)”;
button2.innerText = “Buy weapon (30 gold)”;
button3.innerText = “Go to town square”;
button1.onclick = buyHealth;
button2.onclick = buyWeapon;
button3.onclick = goTown;
text.innerText = “You enter the store.”;
}

///

Hi,
I think the repetition that the instructions are referring to are the reassignments of .innerText and .onclick elements - goTown() and goStore() functions do the exact same task, they just assign different values.
The steps after that one show how to write a function that replaces those reassignments. Given there are more than two locations in this project, it saves you writing basically the same eight lines of code for every location:)

1 Like