0
I want to create a square pattern with for loops.I managed to create rows but the columns went under the rows,how to fix that?
2 ответов
+ 1
Simple way: Take a string variable and add "*" to it in loop. .
After the loop display string.
console.log() adds new line character after output so goes to next line..
0
u can use either:
1- repeat method:
let nrows = 5
for(let i=1;i<=5;i++){ console.log('*'.repeat(nrows)); }
2- joining an array:
let nrows = 5
for(let i=1;i<=5;i++){ console.log(Array(nrows+1).join('*')); }