The @Lal's answer is the answer (I wrote the same in a comment).
But, I suggest another way:
Instead of using the while cycle you can use a setInterval, in my opinion to create a counting table for kids the user experience is more important then performance:
take a look to this code:
var counting = function(){
var myCount = 1;
document.getElementById('main').innerHTML += myCount + "<br/>";
var _timeout = setInterval(function(){
myCount++;
document.getElementById('main').innerHTML += myCount + "<br/>";
if(myCount == 10) clearTimeout(_timeout)
},1000)
}
This function set a timer that every 1000 milliseconds (1 second) show you a new number so as to allow time for the child to count.
Look this example: https://jsfiddle.net/Frogmouth/bke47w3u/2/
if(myCount == 10) clearTimeout(_timeout) stop the timer when myCount is 10.
Add Cell to a table:
If you need to add the number like cell of table simply change the html container #main:
<table id="main"></table>
and the html printed by .innerHTML:
document.getElementById('main').innerHTML += "<tr><td>" + myCount + "</td></tr>";
This show you a table with 1 cell for each rows for a total of 10 rows.
Example: https://jsfiddle.net/Frogmouth/bke47w3u/5/
<script>, not like in your example). What is the problem with your code? The title of your question seems to suggest you want to show the source of the function itself, but that might just be unfortunate wording.document.getElementById('main').innerHTML = countTotal;todocument.getElementById('main').innerHTML += countTotal + "<br />"