I'm trying to build a simple yes/no diagnostic tool as part of learning Javascript. I'm coming absolutely unstuck on how to dynamically target an object's properties based on an external variable such as 'stage'.
For example,
Visually Stage 1 has a title and two buttons. When I select one of the buttons (say yes), the information is replaced with the stage 2 yes information.
So far I've created my objects (what I'm using to hold the info for each page).
function stage (name, title, button1, button2) {
this.name = name;
this.title = title;
this.button1 = button1;
this.button2 = button2;
}
var Stage1A = new stage ('Stage1A', 'success', 1, 2);
var Stage1B = new stage ('Stage1B', 'failure', 1, 2);
Now I'm trying to access the information inside each object based on the current stage number.
var stageNumber = 1;
function myFunction(){
document.getElementById("title").innerHTML = ("Stage"+stageNumber+"A").title;
}
This returns a result of undefined. Can anyone point me in the right direction?