var i = 1;
while(i < 100){
i *= 2;
document.write(i + ", ");
}
So it writes:
2, 4, 8, 16, 32, 64, 128,
What would the simplest way to take the comma off after it writes 128?
var i = 1;
while(i < 100){
i *= 2;
document.write(i + ", ");
}
So it writes:
2, 4, 8, 16, 32, 64, 128,
What would the simplest way to take the comma off after it writes 128?
What would the simplest way to take the comma off after it writes 128?
This simplest way to remove output is to not output it. One solution is to print the first value before the loop starts then write the comma before the value in the loop:
var i = 2;
document.write(i);
while(i < 99){
i *= 2;
document.write(", " + i);
}
Do the comma as a prefix for everything but the first number
var i = 1; while(i < 100){
i *= 2;
document.write((i == 2 ? "" : ", ") + i);
}
So it writes:
2, 4, 8, 16, 32, 64, 128,