Programming Videos

  • View all videos
  • blank
  • Loops in JavaScript
    mrdaniel published this on 1/3/16 | javascript, loops
    Comments
  • +
  • 7
  • -
  • @julieaemoon, so because we are splitting the string into an array at each character (str.split('')) then str.length will be equal to arr.length. You can see that result via the following code snippet:
    "Hello world".length === "Hello world".split('').length
  • +
  • 3
  • -
  • Hey mrdaniel, ive been coding for only a few months but in my experience ive pretty much only been using for-loops, can you explain further on situations that would be more useful to use a while-loop?
  • +
  • 2
  • -
  • @idirir If you are using Chrome browser type `chrome://extensions/ ` into your address bar it will open your chrome extension page. Then search for a extension called ` Scratch JS ` install it. After installing it, open your chrome dev tools and you should see Scratch JS in the same navbar as " Elements...Console...TImeline...Audits...Scratch JS...". This will allow you to type along if you like and run the code. You will have to put a console.log() around whatever you want to ouput. So in his examples you would have to put console.log(arr) for example. With the Scratch JS open, press the three dot icon and click show console drawer that is where you will see the output. Another upside is that you can use ES2015/ES6 syntax as your learning progresses.
  • +
  • 1
  • -
  • Hi mrdaniel, I'm also new to javaScript and I wsa wondering since we turned the string into an array, in the for loop why are we setting i<str.length? Why isn't it set to i<arr.length? Is it because we want to turn it back to a string with the join method? Thanks in advance!
  • +
  • 1
  • -
  • @DaronJS, A while loop is good for when you're not sure how long you may need to loop over something. For example, if you have data continuously coming in from some user (via keyboard input for example), then a while loop could be used. If, on the other hand, you need to loop through a fixed-size array or something similar, then a simple for loop can be used.
  • +
  • 0
  • -
  • hi everyone I am new here. how do I go along with the tutuorials is there a built in IDE like teamtreehouse's
    Log in to submit a comment.