Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your syntax is correct, as verified by running the JavaScript code (exactly as you wrote it) inside Codecademy Labs. If your while loop isn't working, I suspect it has to do with your environment or the state of the document being written, but it is not the code itself. As a fellow newbie, I try running code in two IDE's (codecademy labs being one) to test a lot of code and confirm against this sort of issue, though codecademy can't do file operations.</p> <p>In addition, if you're interested in knowing why a <code>for</code> loop is superior to <code>while</code> for this situation, continue reading.</p> <p>A <code>for</code> loop is a loop that comes in handy when you have a fixed index; When you know how many iterations you need, or know how to find out and can work that into the code.</p> <p>A <code>while</code> loop is better at handling situations when an unknown (and unpredictable) number of iterations is required, as it will loop through until the conditions are eventually met. </p> <p>Keep in mind that what makes it strong also makes it weak; <code>for</code> loops are harder to create infinite loops for. Because of the arguments in a <code>for</code> loop (IE: <code>for (index,index&lt;=value,value++)</code>), most <code>for</code> loops self-terminate neatly, or at least it's hard to forget to put the "closing" condition in. <code>while</code> loops, however, don't innately ask for a closing statement and thus you <em>must</em> explicitly state them inside the loop.</p> <p>I hope this answers your question, and more.</p> <p>EDIT: Oh yeah, and <code>&lt;/br&gt;</code> doesn't work inside the quotes. You can remove it, and it should still do a new line without it; But leaving <code>&lt;/br&gt;</code> inside the code just has it literally print <code>&lt;/br&gt;</code> in the line.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload