I'm learning basics of JavaScript. I try to code a program that logs the following scheme to the console:
*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*
I managed to get first half of the task by the code:
var x = 5;
var line;
for(var i = 0; i<x; i=i+1){
line = "";
for(var j=0; j<x; j=j+1){
if(j <= i){
line = line + " * ";
}
}
console.log(line);
}
So it looks like:
*
* *
* * *
* * * *
* * * * *
Could anybody give me a hint how to get the secod part of the scheme? I'd like to use another loop like the one I have but to revert it's action so that there would be less and less stars in each line.
linedifferently. Instead of settinglineto an empty string, you need to set it something like* * * *, and then remove one star on each round. It doesn't matter, ifiis increased or decreased in the loop, as long as the loop just stops after a correct count of rounds.