0

So I have a scoreboard for a game I am making, if you press a button you get one point, this is the scoreboard. But I want to have it so that if you reach 10 points, you are taken to an other html, a victory screen.

This is my JS + HTML

<script type="text/javascript">
                var clicks1 = 0;
                function updateClickCount1(){
                    document.getElementById("clickCount1").innerHTML = clicks1;
                }
            </script>
            <button type="button" onclick='clicks1++;updateClickCount1()' id="push"> Score +1 </button>
            <div id="clickCount1">0</div>
        </div>
  • Possible duplicate of [How do I redirect with Javascript?](http://stackoverflow.com/questions/4744751/how-do-i-redirect-with-javascript) – Liam Dec 16 '16 at 11:18

3 Answers3

0

Check the value within the function and redirect if it reached 10.

<script type="text/javascript">
    var clicks1 = 0;
    function updateClickCount1(){
        document.getElementById("clickCount1").innerHTML = clicks1;
        if(clicks1 == 10)
          window.location = 'newpahe.html';  
    }
</script>
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
0
<script>
    var clicks1 = 0;
     function updateClickCount1(){
       document.getElementById("clickCount1").innerHTML = ++clicks1;
        if(clicks1>9) window.location.href="victory.html";
     }
</script>

you can do like this set your counter as 0, increment it after user reach the score greater than 9 redirect to the victory page

Man Programmer
  • 5,300
  • 2
  • 21
  • 21
0

Inside your update function, check if the number of clicks is greater or equal than 10. if it is the case use window.location to redirect

var clicks1 = 0;

function updateClickCount1() {
  document.getElementById("clickCount1").innerHTML = ++clicks1;
  if(clicks1 >= 10)
    window.location = "victory.html";
}
<button type="button" onclick='updateClickCount1()' id="push">Score +1</button>
<div id="clickCount1">0</div>
Weedoze
  • 13,683
  • 1
  • 33
  • 63