JavaScript: I think my Solution is from the Gods and I'm not impressed

:joy: :joy: Hi guys so I’m doing the Eloquent JavaScript, and this was exercise one:
Write a loop that makes seven calls to console.log to output the following

(This is supposed to be 7 rows of #, but the editor seems not to be showing all row)
and this was my solution:

1 let start = “”;
2 let counter = 0;
3 for (i = 0; counter < 7; counter++) {
4 start = start + “#”;
5 console.log(start);
6 }
got it after a coupl’a times of trying. But I seem not to be understanding my logic especially from the first variable declaration. Can you guys please point out if there’s anything wrong with the code and how you could have done it. The Author’s solution used the length method, which I understand and proud of because of it’s efficiency and efficiency is what we’ve be taught here at the Camp:
1 for (let line = “#”; line.length < 8; line += “#”)
2 console.log(line);

Cheers guys have an awesome weekend- Siya from South Africa.

I think your solution is correct, I used it and it works fine, but change the quotes ("") to a single quote (’’) because it marked a syntax error.
In the first variable declaration, you are indicating that there is a “start” variable that does not have an assigned value and when you enter your loop you are adding a “#” on each iteration.

1 Like

I see. Thank you for your review, guess it’s this solution forms part of the popular phrase " there are many ways of doing things" :smiley:

Cheers buddy.

1 Like