Simplify Repetitive Tasks with Loops
The Refactor Challenge Solution
Here is my solution. https://w.trhou.se/e7wwgfbezt
Technically your code works, the result is the same, and you did nothing wrong, but...
Putting document.write inside the loop means that every time a single lap of the loop runs, something is written in your html, and that can potentially slow down your program. Putting document.write outside the loop means that the program only writes to the page once, when the entire string is complete. In my opinion it's a more optimal approach.
Think of it this way - if you need 10 bottles of water, you can go to the store 10 times and bring back a bottle each time, but wouldn't it be more rational to go to the store once, stuff all 10 bottles in a bag and bring all 10 of them back at once?
Posting to the forum is only allowed for members with active accounts.
Please sign in or sign up to post.
I forgot my password