Jump to content

Search the Community

Showing results for tags 'while loop'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Job Boards
    • Jobs
  • Community Lounge and FAQ
    • Forum News
    • Open Forum
    • New Members Forum - Start Here!
  • Entrepreneurship, Business and Marketing
    • Social Media Marketing & Web Marketing
    • Entrepreneurship
    • Career Questions - Asked and Answered
  • StudioWeb
    • StudioWeb
    • StudioWeb News
    • StudioWeb Projects
  • Programming
    • Python
    • Javascript
    • PHP
  • Web Design
    • Beginners Web Design
    • HTML/XHTML
    • Dreamweaver
    • CSS
    • Advanced Web Design
    • Business of Web Design
    • Web Design News
  • Miscellaneous
    • Cybersecurity
    • Miscellaneous Software
    • Blogs and CMS
    • Web Accessibility
    • Peer-to-Peer Reviews
    • Website Templates
    • Web Design Jobs
    • Test Forum
  • Archives
    • Beginners Web Design
    • Course: The Complete Entrepreneur
    • Web Accessibility
    • Photoshop
    • CSS
    • Forum Rules and Etiquette
    • Flash
    • ASP
    • General Programming
    • Expression Web
    • Beginners Ruby
    • Killersites University
    • Actionscript
  • Uncle Stef's Mentoring Club's *** Getting Started ***

Categories

There are no results to display.

There are no results to display.

Product Groups

  • Business & Entrepreneur Courses

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website


LinkedIn


Facebook


Twitter


AIM


Yahoo


Other


Location


Interests

Found 2 results

  1. I expect the browser to print the values from 10 to 1 in an empty p tag using JavaScript, but it's printing 1 to 10. Why does it print above the old line, and not below it? <!-- Button for printing "i" --> <input type="button" value="print i"> <!-- Empty p tag where the values of "i" will be printed --> <p></p> <script> // Function for printing "i" function print() { var i = 10; while(i > 0) { // Grabs the empty p tag var p = document.getElementsByTagName("p")[0]; // Prints the values of "i" on the p tag p.innerHTML = "i: " + i + "<br>" + p.innerHTML; i = i -1; } } // Calls the function for printing "i" document.getElementsByTagName("input")[0].onclick=function() { print(); } </script> test-standalone.html
  2. I have two question about JS loops. Its about while loops. 1)if we type this line of code target.innerHTML = "LoopCount: " + loopCount + "<br>" + target.innerHTML; why does it write from lowest number to highest like this? LoopCount: 1 LoopCount: 2 LoopCount: 3 LoopCount: 4 LoopCount: 5 The function tells that starting loop is 5,we are targeting empty paragraph with id "target", then writting into it some text and saying that we want to see current loop number, which is 5 at the beginning , then we are substracting 1 from it(decrementing), and repeating, writing and so on again, so why doesnt it goes backward, 5,4,3,2,1? Why the first number is 1 when the starting was 5? My logic tells me if you start with 5, then print current number and then decrement it, and repeat it again all over , it should go in 5,4,3,2,1 order. function doItAgain(message) { var loopCount = 5; while(loopCount > 0) { var target = document.getElementById("target"); target.innerHTML = "LoopCount: " + loopCount + "<br>" + target.innerHTML; console.log("LoopCount is now: " + loopCount); loopCount = loopCount -1; } console.log("End loop"); var button = document.getElementById("looper"); button.value ="Done looping!"; 2) if we look at opposite case and write target.innerHTML = "target.innerHTML + "LoopCount: " + loopCount + "<br>" ; then it writes LoopCount: 5 LoopCount: 4 LoopCount: 3 LoopCount: 2 LoopCount: 1 But if we look the order into syntax, shouldnt it write this? 5 LoopCount: 4 LoopCount: and so on....
×
×
  • Create New...