I have a script that contains 3 questions. I have started by creating 3 variables (ex: var q1 = “question here”) and I have a function that randomly picks a number between 1 and 3 and chooses that question (var question = “q” + rand;) but if I want to reference this variable called question to output the question in HTML (ex: document.getElement.Id(“output”).innerHTML += question;) how would I do so?
Here is my code:
// Questions List
var q1 = " Question 1 here"
var q2 = "Question 2 here"
var q3 = "Question 3 here"
// Randomly generate a question and then output it
var randy = Math.floor(Math.random()*3+1);
var question = "q" + randy;
document.getElementById("output").innerHTML += question;
<!doctype html>
<html>
<body>
<div id="output"></div>
</body>
</html>
So basically the script will choose a question from 1 to 20 and output it to my HTML div tag.
Sorry if this isn’t clear. Any help is greatly appreciated.