Note that there are some explanatory texts on larger screens.

plurals
  1. POTable Refresh, Every Second
    text
    copied!<pre><code>&lt;html&gt; &lt;body&gt; &lt;body bgcolor="33FF00"&gt; &lt;script language = "JavaScript"&gt; //-----------------Created Variables Here------------------ timeLeft = 30 //this is counted down from until it hits 0 points = 0 //this is the points system that is added to by 10 each time a duck is clicked // ----------------Duck Or Sky element----------------- function duSky(){ //This is a function to tell add points to the points variable if the user clicks a duck. duckNum = Math.floor((Math.random()*10)+1) if(duckNum&lt;10){document.write("&lt;img src=images/skyTile.jpg&gt;")} else{document.write("&lt;img src='images/duckTile.jpg' onClick='duckClick()'")} } &lt;/script&gt; &lt;center&gt;&lt;img src=images/duckHuntTitle.gif&gt;&lt;br&gt; &lt;!Duck Hunt title gif, no background so you can see the background of the page, also centered&gt; &lt;div name = "tableDiv"&gt; &lt;!Named the table "TableDiv" so that I can refer to it at a later date. This was to try and make my job of refreshing easier&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;/tr&gt; &lt;!Inside of all the table boxes there is a function that designates whether inside will be a duck or sky tile&gt; &lt;tr&gt; &lt;!This is the duck table that is exactly 1000px wide by 400px height. This is created by 10 200px by 200px boxes, two rows of 5 boxes&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;td&gt; &lt;script&gt; duSky() &lt;/script&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;form name="score"&gt; Points &lt;input type="text" name="pointsscored" readonly="readonly"&gt; &lt;!This is the box that is centered that displays the points the player has got, also is now readonly so no tweaking is allowed&gt; &lt;/form&gt; &lt;form name="timer"&gt; Time &lt;input type="text" name="timeBox" readonly="readonly"&gt; &lt;!This is the timer box that is centered as well that displays how long the player has left and is readonly&gt; &lt;/form&gt; &lt;/center&gt; &lt;script language = "JavaScript"&gt; //Returns the script to JavaScript to allow for functions to be used that are related to the HTML previous to this document.timer.timeBox.value = timeLeft //Displays the time left before the game has even started and been clicked so the player immediately knows the time that they have to play with function timeDecrease(){ //This is the timer function that reduces the timer by a second each time to make the game slowly time out after 30 seconds setInterval(function(){timeLeft-- //I am still working on the refresh function but hopefully it will be corrected to make the table refresh with every 1000 miliseconds document.timer.timeBox.value=timeLeft; //document.tableDiv.reload(true) //trying to get the reload function to work. },1000); //1000 miliseconds, therefore it is 1 second } while(timeLeft &lt; 0){alert("Timeeeeeees Up, you scored: ", points ,"points! well done Duck Slayer!")} //Alert to signify the end of the game. // ----------------Function for clicking the duck----------------- function duckClick(){ points = points + 10; document.score.pointsscored.value = points; //when the player clicks the duck, points will be added to the points box } &lt;/script&gt; &lt;center&gt; &lt;form name = "playButton"&gt; &lt;button type="button" onClick = "timeDecrease()"&gt;Play!&lt;/button&gt; &lt;!This is the on click function that starts the game/countdown feature&gt; &lt;/center&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I have a problem with getting my graph to work. I am currently working on making a simple point and click game and I need the table to refresh to make the images become randomized in the position. The idea is that it refreshes every second, giving the appearance of true randomization from a previous section of the script. The problem is that I can't get the table to refresh even though I have set a div tag and I am using the reload function. I am hoping that you can help me find a solution to this.</p> <p>Also the website doesn't recognise the <code>document.tableDiv.reload(true)</code> part but I don't understand how to get the table to refresh with every second that goes past.</p> <p>P.S if you haven't guessed I am awful at coding but hope to get better.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload