You were almost there:
for (i = 1; i <= 7; ++i) {
for (j = 1; j <= 7; j++) {
if (j <= i)
document.write(j);
else
document.write("*");
}
document.write(" ");
}
Your code with comments:
for (i = 1; i <= 7; ++i) { // This for should loop over your blocks
document.write(i); // Doing this will make the first number change for every block.
for (j = 1; j < 7; j++) { // This for should loop over your numbers
if (j <= 7) { // This if is only there for the space? Put it in the other loop!
document.write("*");
} else {
document.write(" ");
}
// Here you should check if you want a * or a number. Not the check to see if you want a space or not.
}
// Space should be here.
}
solved For loop generating numbers with asterisks [closed]