JSFiddle - React, Tailwind, and code Playground
by bjelline
HTML
<!-- Question -->
<p id="question"> </p>
<!-- Answer Array -->
<ul id="answers"> </ul>
JavaScript
var question = ["what"];
var currentQuestion = 0;
var answers = [
["this", "that", "something else"]
];
var elementQuestion = document.getElementById("question");
var elementAnswers = document.getElementById("answers");
function been_clicked() {
alert("You clicked " + this.id
+ " '" + this.innerHTML + "'");
}
elementQuestion.innerHTML = question[currentQuestion];
for (a = 0; a < answers[currentQuestion].length; a++) {
var li = document.createElement("li");
li.innerHTML = answers[currentQuestion][a];
li.id = "answer_" + a;
elementAnswers.appendChild(li);
li.addEventListener("click", been_clicked, true);
}