# Javascript - Stars exercise

**URL:** <https://forum.codewithmosh.com/t/javascript-stars-exercise/6617>\
**Category:** Uncategorized\
**Created:** [August 6, 2021, 3:46pm UTC](https://forum.codewithmosh.com/t/javascript-stars-exercise/6617 "2021-08-06T15:46:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NathanielKhallil](https://avatars.discourse-cdn.com/v4/letter/n/898d66/32.png) [@NathanielKhallil](https://forum.codewithmosh.com/u/NathanielKhallil)\
**Post date:** [August 6, 2021, 3:46pm UTC](https://forum.codewithmosh.com/t/javascript-stars-exercise/6617/1 "2021-08-06T15:46:50Z")

</div>

While I understand why it is solved the way it is with nested for loops, this is the solution I put together:

showStars(5);

function showStars(rows) {  
for (let row = 0; row \<= rows; row++)  
if (row)  
console.log(’\*’.repeat(row));  
}

‘if row’ is just to stop the initial blank from the row = 0; otherwise, it produces the same result.

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [August 6, 2021, 4:29pm UTC](https://forum.codewithmosh.com/t/javascript-stars-exercise/6617/2 "2021-08-06T16:29:22Z")

</div>

> [@NathanielKhallil](#):
>
> ‘if row’ is just to stop the initial blank from the row = 0

So why are you starting your loop with row 0 anyway? You could start with row 1 and don’t need that `if` anymore.

And BTW: Read about [how to format code in the forum](https://forum.codewithmosh.com/t/code-formatting-and-syntax-highlighting/186/3).

---

<div class="post-metadata">

**Author:** ![NathanielKhallil](https://avatars.discourse-cdn.com/v4/letter/n/898d66/32.png) [@NathanielKhallil](https://forum.codewithmosh.com/u/NathanielKhallil)\
**Post date:** [August 6, 2021, 6:44pm UTC](https://forum.codewithmosh.com/t/javascript-stars-exercise/6617/3 "2021-08-06T18:44:12Z")

</div>

Honestly, I just didn’t want to start with row = 1. What if someone entered 0 into the function or anything that was not a number? That was my initial thought, but I later realized it would not print anything to the terminal in those cases. I checked out the formatting link and will be sure to do so in future.
