Jump to content
Killersites Forums

hiimrann

New Members
  • Content Count

    2
  • Joined

  • Last visited

Everything posted by hiimrann

  1. It's alright, I worked it out with a little help. If anyone's wondering, the answer is in the following line of code: p.innerHTML = "i: " + i + "<br>" + p.innerHTML; I'll explain it with two iterations, in four steps each. Hopefully I got it right, and explained it in non-nerd well lol. [Iteration 1] Step 1. When i = 10, the browser prints the following in the <p> tag: i: 10 <br> Step 2. p.innerHTML (right of the = operator) is empty for now, hence, nothing happens on the screen in this step. Step 3. The printed line (i: 10 <br>
  2. 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.
×
×
  • Create New...