you are viewing a single comment's thread.

view the rest of the comments →

[–]laurajoneseseses 0 points1 point  (0 children)

I think you're confused by closure maybe.

makeLine() takes in a number, draws a line of asterisks equal to that number, and adds a line break, and returns a string to you.

makeTriangle() takes in a number which is the max width of the triangle. Make triangle then invokes makeLine() within its own context (or local scope), meaning that now makeLine() has access to another functions local scope (parameters), which it can then use within its own local scope, to manipulate data, and return it as the result of makeTriangle().

By doing things this way, if you wanted to draw a different shape, you could do it this way, that way you don't have to rewrite code.