Here is some sample code of what I am trying to achieve:
pingpong = {
paddleA: {
speed: 5,
},
paddleB: {
speed: 6,
},
paddleAI: {
AI1: "paddleA",
AI2: "paddleB"
}
}
paddleAI = pingpong.paddleAI;
paddleA = pingpong.paddleA;
paddleB = pingpong.paddleB;
for (paddle in paddleAI) {
document.write(paddleAI[paddle].speed);
}
When I run this code, it returns "undefined"
I am trying to use the text values in paddleAI
as which paddle's speed I want to access.
How would I get that code to return the speed values of paddleA
and paddleB
?
Note: This is only demonstration resembling my actual code, therefore I don't have much room to dramatically restructure how I am storing and accessing my values.