Put the numbers 1 through 100 in ascending order using the for statement, but the number 50 shouldn't appear. How to solve?
-
<!DOCTYPE html> <html> <head> <title>JS</title> <script language="JavaScript"> for (var a = 1; a <= 100; a++) { if(a==50) { a.replace('') } if(a==49) { document.write(a++); } document.write(a + '<h2 style="color: blue">'); } </script> </head> <body> </body> </html>
JavaScript Anna Sparks, Jul 13, 2019 -
for (let a = 1; a & lt; 100; a ++) {
if (a === 50) {
continue
}
document.write (`$ {a}`)
}Juliette Keller -
<!DOCTYPE html>
<html>
<head>
<title>JS</title>
<style>
b {
color: blue;
padding: 0 3px;
}
</style>
<script>
for (var a = 1; a <= 100; a++) {
if (a != 50) {
document.write('<b>' + a + '</b>');
}
}
</script>
</head>
<body></body>
</html>Anonymous -
Just write a normal loop without conditions so that ALL the numbers appear (I really didn't understand where), and then add
if (a === 50) continue;
and allAnonymous
3 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!