-1
Good night! In my practical Javascript experiences, I tried to create a condition to alert the user about a variable he missed by pressing the key enter twice. However, in trying to solve this problem, I made two attempts:
/*Tentativa 1:*/
var linha = Array(3,3);
var x, y;
for (x = 0; x < 3; x++) {
for (y = 0; y < 3; y++) {
linha[x,y] = parseInt(prompt("Digite o "+[y+1]+"º número da "+[x+1]+"º coluna"));
if (linha[x,y] == null) {
alert("Digite alguma coisa");
while (linha[x,y] == null){
linha[x,y] = parseInt(prompt("Digite o "+[y+1]+"º número da "+[x+1]+"º coluna"));
if (linha[x,y] == null) {
alert("Digite alguma coisa");
}
}
}
}
}
/*Tentativa 2:*/
var linha = Array(3,3);
var x, y;
for (x = 0; x < 3; x++) {
for (y = 0; y < 3; y++) {
linha[x,y] = parseInt(prompt("Digite o "+[y+1]+"º número da "+[x+1]+"º coluna"));
if (linha[x,y] == " ") {
alert("Digite alguma coisa");
while (linha[x,y] == " "){
linha[x,y] = parseInt(prompt("Digite o "+[y+1]+"º número da "+[x+1]+"º coluna"));
if (linha[x,y] == " ") {
alert("Digite alguma coisa");
}
}
}
}
}
Question: Which method is most feasible to solve this problem above?
Set this problem aside a little and remove the snippets of code you entered trying to solve this. Make the rest work first. You may think you are working, but you are not. Run this code in a Debugger or REPL and enter the values of the variables. Your array is being initialized incorrectly and
linha[x,y]
doesn’t do what you think.– bfavaretto
But @bfavaretto, in this case I’m assembling an array with Array(). If I put the project proposal related to this algorithm that I’m mounting here on the forum, the moderators will cancel the post.
– pe.Math