Trying to create a high score of the fastest time for my HTML game

html score counter
game over javascript
javascript high score script
high score text file python
how to end a game in javascript
var score = 0 meaning
how to make a high score file in python
javascript scorekeeper

So I'm making this reaction game where the player has to click a box as fast as possible. I've displayed the time taken to click the box but I'm trying to displayed the fastest time the player has clicked a box. I would really appreciate your help.

Here's my code:

<body>
    <div>
        <p>Your time: <span id="time"></span></p>
        <p>Highscore: <span id="highscore"></span></p>
        <div id="shape"></div>
    </div>
    <script>
        var start = new Date().getTime();
        function makeShapeAppear() {
            document.getElementById("shape").style.display = "block"
            start = new Date().getTime();
        }
        function appearAfterDelay() {
            setTimeout(makeShapeAppear, 1000);
        }
        appearAfterDelay();
        document.getElementById("shape").onclick = function() {
            var end = new Date().getTime();
            var timeTaken = (end - start)/1000;
            document.getElementById("shape").style.display = "none";
            document.getElementById("time").innerHTML = timeTaken + "s";
            appearAfterDelay();
        }
    </script>
</body>

To summarize, I want to display the shortest "timeTaken" variable in the highscore id. Thank you in advance.

Store your last time taken if no highscore, if the new time taken is less than your highscore then set the highscore to be the timetaken. Like this.

#shape{
  width: 200px;
  height: 200px;
  background-color:red;
}
<body>
  <div>
    <p>Your time:
      <span id="time"></span>
    </p>
    <p>Highscore:
      <span id="highscore"></span>
    </p>
    <div id="shape"></div>
  </div>
  <script>
    var highscore;
    var start = new Date().getTime();
    function makeShapeAppear() {
      document.getElementById("shape").style.display = "block"
      start = new Date().getTime();
    }
    function appearAfterDelay() {
      setTimeout(makeShapeAppear, 1000);
    }
    appearAfterDelay();
    document.getElementById("shape").onclick = function () {
      var end = new Date().getTime();
      var timeTaken = (end - start) / 1000;
      highscore = (timeTaken < highscore || !highscore ? timeTaken : highscore);
      document.getElementById("shape").style.display = "none";
      document.getElementById("time").innerHTML = timeTaken + "s";
      document.getElementById("highscore").innerHTML = highscore + "s";
      appearAfterDelay();
    }
  </script>
</body>

Saving the highscore for a python game, import pickle # load the previous score if it exists try: with open('score.dat', 'rb') as file: on reading and writing to files: http://docs.python.org/2/tutorial/inputoutput.​html you end the game, and then load the same file the next time you start the game. You can use a dict to hold your highscore and simply write it into a file: The current time doesn't need to be a cloud variable as you're only storing it if it beats the current best time so you store it as the high time or low time. In most cases therefore a single cloud variable will be enough.

I would suggest using cookies. Each time the user clicks the box, check if cookie exists, if not create one with time value. If it does exist compare its value to current one and depending on if it is lower update the cookies value.

Track the score and win, If you can see your score throughout the game, eventually you can impress your friends. You need a variable to record the score. also need a drawScore() function, to create and update the score display. the value of the score variable each time a collision is detected. JavaScript; HTML; CSS; Result. The syntax for writing text on a canvas element is different from drawing a rectangle. Therefore we must call the component constructor using an additional argument, telling the constructor that this component is of type "text".

If you want to show "the fastest time the player (singular) has clicked a box" and you want to keep that value despite user close and open the browser or tab you could use localStorage or sessionStorage.

localStorage.setItem("bestTime", timeTaken);

and

var bestTime = localStorage.getItem("bestTime");

if(timeTaken > bestTime){
localStorage.setItem("bestTime", timeTaken);
}

This approach stores the info in the browser. If you want to store the fastest time players (plural) have clicked or save the data to use in different browsers, you need to use a database storage.

Windows 7 All-in-One For Dummies, Right-click the same square a second time and you plant a question mark on the square Whenever you want to see the best times and who holds the records, choose Game➪Statistics. worldranking.html for the best-ever Minesweeper scores. My guess is that Microsoft figured it would try to make money with games on  I am developing a simple HTML game and each page has a single question. How do I keep score so that if the person gets the correct answer, the score is incremented and then when the game is over or the wrong answer is selected within the game, the game over page it shows the score.

JavaScript Performance, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java  Javascript simple quesiton game, update score So I'm trying to update the score each time the person answers correctly. My code right now displays the correct score on the screen multiple times beside each other.

Scratch Tutorial, Today we go over how to make a high score system in scratch easily and quick! I tried to m Duration: 2:38 Posted: Apr 22, 2018 This android and IOS game is very addictive and fun six. Six.io how to get the high score EVERY TIME Android game Dan Cook Peppa Pig Official Channel 🚀 Peppa Pig's Fun Time At The Space

High Score Table with Saving and Loading (Unity Tutorial for , If playback doesn't begin shortly, try restarting your device. Click here to visit our frequently Duration: 17:12 Posted: Feb 22, 2019 I kid you not. Today I was casually talking to my friend when all of a sudden he wanted to showe something. He told me that I would be shocked to know his highscore in the dino game but we were eating at that time.

Comments
  • Can you give a codepen link?
  • You haven't specified an actual problem regarding the code shown. You mentioned a goal but that doesn't tell us what does or doesn't work within your code. Take a few minutes to read How to Ask
  • That worked beautifully. Thank you so much for your help!