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
triangle:
#######
(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.