The showStars Exercise on Mosh tutorial on javascript

showStars(10);
function showStars(rows) {
let star = " ";
for (let i = 1; i <= rows; i++) {
star += “*”;
console.log(star);
}
}

The code above works perfectly well as Mosh’s nested loop solution below

showStars(10)
function showStars(rows){
for(let row = 1; row <= rows; row++){
let pattern=" “;
for(let i = 0; i < row; i++)
pattern +=”*";
console.log(pattern);
}
}

Is this possibly a simpler code i just discovered ??

1 Like

I did the same as you and I think it’s a simplier solution.
But in my opinion, the purpose of his solution was to introduce the nested loops for the next exercise.