Web Analytics Made Easy -
StatCounter Why are they undefined? - CodingForum

Announcement

Collapse
No announcement yet.

Why are they undefined?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why are they undefined?

    I'm working on a coding bootcamp course and I'm struggling on a lesson about loops. I'm sure the details of the code are probably far off, but what I really don't get is why I'm getting "forLoop is not defined" and "whileLoop is not defined" messages. If I can get it past that point the point of being undefined, atleast the new errors will give me more helpful hints. I've asked for help a few times but have gotten nowhere. Any help is appreciated.


    function forLoop(array) {
    for (var i = 1; i < array.length; i++) {
    console.log("I am " + i + " strange loop."}
    }

    function whileLoop(n) {
    while (n > 0){
    console.log(--n)}
    }

  • #2
    even creating a variable array and assigning it a number isn't helping.

    Comment


    • #3
      Code:
      <script type = "text/javascript">
      var array = [1,2,3,4,5];
      function forLoop() {
      for (var i = 1; i < array.length; i++) {
      alert (i + " strange loop.")
      }
      }
      forLoop();
      
      
      function whileLoop(n) {
      while (n > 0) {
      alert (--n)}  // note subtraction takes place before evaluation of n
      } 
      whileLoop(10);
      
      </script>
      Quizmaster: After defeating Tony Abbott in a leadership contest in 2015, Malcolm Turnbull became prime minister of which country?
      Contestant: Scotland.

      All the code given in this post has been tested and is intended to address the question asked.
      Unless stated otherwise it is not just a demonstration.

      Comment

      Working...
      X