By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 941 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

List of numbers 1-10 not appearing.

P: 6
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Hello, HTML!</title>
  5.     <script> 
  6.          function countToTen() {
  7.             var count = o ;
  8.             while (count < 10) {
  9.                 count ++ ;
  10.                 document.getElementById("theCount").innerHTML += count + "<br>";
  11.             }
  12.         }
  13.         Code-Line Before Listing Code </script>
  14.         </head>
  15.         <body onload="countToTen();">
  16.             <h1>Let's Count to 10 with Javascript!</h1>
  17.             <p id="theCount"></p>
  18.         </body>
  19.         </html>
On the browser only 'Lat's count to ten with JavaScript!' appears but the list of numbers does not.
Please help. Regards
Jan 9 '19 #1

✓ answered by gits

why do you initialize the variable count with another undefined variable o?

and that Code-Line Before Listing Code in the script section breaks the code as well if its really there and not just a copy and paste error.

Share this Question
Share on Google+
3 Replies


gits
Expert Mod 5K+
P: 5,235
why do you initialize the variable count with another undefined variable o?

and that Code-Line Before Listing Code in the script section breaks the code as well if its really there and not just a copy and paste error.
Jan 9 '19 #2

P: 6
Hi! Thanks for your support Gits. I am only pasting a code as advised by a book I am learning from. Have checked the code for every comma etc and it is the absolute copy as printed in the book. However am not getting the numbers printed. Am using sublimeteaxt editor, what should the code be for listing? shouldn't <Li> command be used somewhere? Do continue your support.Appreciate much.
Jan 9 '19 #3

gits
Expert Mod 5K+
P: 5,235
well i gave you the answer already: remove that mentioned text in the script section and initialize the variable count correctly - then the code will run and do what it should.

PS: the code simply adds the count as plain text to a <p>-element which probably is enough for the sake of 'outputting' something - of course you could create new elements and build up a ordered or unordered list or whatever you want to do with the result. Javascript gives you the possibility to manipulate the DOM of a html document in nearly any way you want.
Jan 9 '19 #4

Post your reply

Sign in to post your reply or Sign up for a free account.