+1 vote
by
<!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>
by
MerCat What's the point of learning and solving problems if you're running to the forum with them?
by

3 Answers

+2 votes
by
for(let a = 1; a<100; a++){ <br/>
if (a === 50){
continue
}
document.write(` ${a} `)
}
+1 vote
by
<!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>
by
You couldn't do it without checking in every iteration?
by
Thank you so much!
by
origami1024 No, okay)))
for (let a of [...Array(101).keys()].filter(val => val > 0 && val != 50)) document.write(`<b>${a}</b>`);
by
origami1024 , you can, but why
by
origami1024 ,
for (var a = 1; a < 50; a++) document.write('<b>' + a + '</b>');
for (var a = 51; a <= 100; a++) document.write('<b>' + a + '</b>');
by
z80b , the bitcoin miner?
+1 vote
by
Just write a normal loop without conditions for ALL digits to appear (I really don't know where), and then add on topif (a === 50) continue;
and that's it
by
Okay. Thank you so much!
by
It seems to me - continue throws off the program logic almost as much as goto. So the variant "take the whole loop body into the if (a != 50) { ... }" seems clearer to me.
by
* Here we just need a < 100. Otherwise the loop will end at 101 (not 100).
by
Karpion What exactly is confusing?
for (var a = 1; a <= 100; a++) {
if (a === 50) continue;
console.log(a);
}
by
I see.
by
Vadim Rublev It is not so difficult to open the console in the browser and simply copy the code
by
The browser won't tell you why the result is like that.

Why iterate if a = 100? The result of this step would be: 101. Why not?
The logic of iteration at a = 99 is clear - the result: 100. Or is it wrong too?
...