1
I tried to use getElementeById but it’s not working.
HTML Quiz
<div class="buttons"> <!--Creating four button element for four options-->
<button id="btn0"><span id="choice0"></span></button>
<button id="btn1"><span id="choice1"></span></button>
<button id="btn2"><span id="choice2"></span></button>
<button id="btn3"><span id="choice3"></span></button>
</div>
function quiz(){
document.getElementById("choice0").value = array[index][1];
document.getElementById("choice1").value = array[index][2];
document.getElementById("choice2").value = array[index][3];
document.getElementById("choice3").value = array[index][4];
}
var array = [ ["Who discovered Brazil?" "Cabral", "Paes", "Garotinho", "Lula"], ... ]
EDIT: Gone Now in the log console takes a look, it seems that the error is this: Uncaught Typeerror: Cannot read Property '1' of Undefined in the array index.
Does it make a mistake? What gives
console.log(array)
? I suggest you create a Minimum, Complete and Verifiable Problem Example to make it easier for the community to indicate the problem and its solution.– Isac
simply looks nothing, nor gives error in the console
– Sanderson Milagres
You already answered the first question I asked. Now we must respond to the second and follow the advice I gave to set an example that shows the problem.
– Isac
At what time/action(ie when) is to change these values ?
– luizricardo6n
@luizricardo6n I tried to put as one of the first actions, but still appearing nothing on the button, I think in this case the position does not matter
– Sanderson Milagres
Where was the
index
and of what value ?– Isac
no value, I used it to pick the position of my vector
– Sanderson Milagres