1
I am trying to create a menu of options for the user to choose one of the 20 previous exercises to open in the browser. Only instead of creating it manually, I use the repeating structure for
with two variables x and i to create this menu automatically. But I wanted to put this text generated by the loop inside a dialog box alert(texto)
. I have tried in many ways, but none of them have succeeded.
First attempt
var x;
var i = 38;
for (x = 0; x < 20; x++) {
texto = (x+1) + "- Exercício" +(i++)+ "\n";
}
var menu = parseInt(prompt(texto));
2nd Attempt
var x;
var i = 28;
document.write("<div id='menu'>");
for (x = 0; x <= 20; x++) {
document.write((x+1) + "- Exercício" +(i++)+ "<br>");
}
document.write("</div>");
var texto = document.getElementById('menu');
var alert(texto);
Third attempt
var x;
var i = 38;
alert("Escolha um exercício para abrir:");
for (x = 0; x < 20; x++) {
var menu = parseInt(prompt((x+1) + "- Exercício " +(i++)+ "\n"));
}
Question: It is possible to create this large menu within a dialog box using only a repeat loop?
Obs. I’m just starting to assemble it, and if any information is missing, don’t disregard this question. :-'