I'm learning basics of Java Script. I want to print the following in the console:
*2345
**345
***45
****5
*****
*****
****5
***45
**345
*2345
I've already wrote 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);
}
for(var i = x; i>0; i--){
line = "";
for(var j=0; j<x; j=j+1){
if(j <= i-1){
line = line + " * ";
}
}
console.log(line)
}
So the result is:
*
**
***
****
*****
*****
****
***
**
*
Could anybody help me to modify the loop? I've tried various things but it never works.