I have script that builds a global variable name, and I need the value of that global variable to be called, instead, it's displaying the text of the variable I built, which is the variable I need to be called. Below is an example of what I mean:
<head>
<script>
var speechCount = 0;
var speech1 = 'This should display';
</script>
</head>
<body>
<div id="speechText" onclick="myFunction()">
Whatever here.
</div>
<script>
function myFunction() {
speechCount = speechCount + 1;
var text = 'speech'+speechCount; <----This is what actually gets displayed (As speech1)
document.getElementById("speechText").innerHTML = text;
}
</script>
So on my page, in the div, it says "speech1" instead of "This should display". How do I force JavaScript to realize I want the global variable value pulled, not the actual value of the text variable? Hopefully this all makes sense!