Looping a triangle
I felt like my grasp of loops wasn't good enough to complete the excercise I was given in Session 3 with Richard. I started to attempt the excercises in Eloquent Javascript to supplement my learning and get a better grasp on how to write the logic that was being asked of me.
Here's the first task:
Write a loop that makes seven calls to console.log to output the following triangle:
############################My solution:
let hash = '#'let counter = 0let prev = hashwhile (counter <= 7) { console.log(hash) hash = hash + prev counter = counter + 1}I thought this was really similar to the fibonnacci problem I was given in Session 1, only this time I think I finally understood how to write operations like this myself:
counter = counter + 1I think I would call this a very small but fun breakthrough.
I now fully understand these lines of code:
let counter = 0while (counter <= 7)counter = counter + 1I understand that I can create a counter that has a value of zero and then manipulate it inside of a loop.
On this task I did not have to google, search or lean on any material other than that in the book. This felt like an enormous achievement given that I easily give up on finding the solution myself and start furiously googling.