Se supone que este código omite el número 7 porque hay una declaración de var usando el operador ===. Mi pregunta es qué necesitamos para que incluya el número 7. ¿Es porque se ha declarado como variable y, por lo tanto, la está ignorando? 7 puede ser una variable ¿verdad? o es un valor entero?
<!DOCTYPE html> <html> <body> <p>A loop with a <mark>continue</mark> statement.</p> <p>loop will skip the iteration where k = 7.</p> <p id="maddy"></p> <script> var text = ""; var k; for (k = 0; k < 10; k++) { if (k === 7) { continue; } text += "The number is " + k + "<br>"; } document.getElementById("maddy").innerHTML = text; </script> </body> </html>Simplemente elimine la declaración if que verifica si k es 7 ?
<!DOCTYPE html> <html> <body> <p>A loop with a <mark>continue</mark> statement.</p> <p>loop will skip the iteration where k = 7.</p> <p id="maddy"></p> <script> var text = ""; var k; for (k = 0; k < 10; k++) { text += "The number is " + k + "<br>"; } document.getElementById("maddy").innerHTML = text; </script> </body> </html>Solo haz una condición simple.
if (k != 7) { text += "The number is " + k + "<br>"; }Echa un vistazo a tu lógica. Está ejecutando un bucle while de 1 a 10. Allí está comprobando si el número es 7 en la condición if y, si eso es cierto, le está diciendo al bucle que finalice esa iteración desde ese punto y que no continúe. Entonces el código nunca llega a [document.getElementById("maddy").innerHTML = text;]. Por lo tanto, no se muestra.