jquery - Add Time To Javascript Game Timer If Condition Met -
edit:
I thought I would try and clarify some I will add Actually what I want is similar to the pole situation: cross the finish line and earn more time. Except this case, you match two numbers.
I want to improve on javascript and jquery, so I thought there would be a great way to go about creating games.
The essence of the game is that you have been given a number and the goal is to match that number. I have all the work, which also includes when the goal is met, this score Now, whatever you want, it is to add 30 seconds to the time when the goal is matched.
I got it to add 30 seconds to internal HTML but there is no countdown. If you were 15 years old then 45 would have been reduced and 14 would go back.
I got the answer and I thought I could change
if (sec == 0) {IsRunning = true; Second + = 2;
turns into my position and seconds = 30 =; Although nothing happens.
This is my code. I am also open for Jquery solution if you prefer to share this
var is wait = false; Var isRunning = false; Var seconds = 120; Var countdown timer; Var finalCountdown = false; Var TargetDiv = document.getElementById ("Target"). InnerHTML; Var totalDiv = document.getElementById ("Total"). InnerHTML; Function Game Timer () {var minute = Math field ((30 seconds) / 60); Var remaining seconds = seconds% 120; Document.getElementById ('TimerID'). InnerHTML = Balance Seacand; If (goalDiv == totalDiv) {isRunning = true; Second + = 30; If (sec == 0) {$ .mobile.changePage ("index.html # youlost", {Infection: "SlideUp"}); ClearInterval (countdownTimer); } Else {finalCountdown = true; }} Else {isWaiting = true; Seconds--; }} CountdownTimer = setInterval (GameTimer, 1000);
It seems that you can assume the value of totalDiv
You can set it up after you start it.
var goalDiv = document.getElementById ("Target"). InnerHTML; Var totalDiv = document.getElementById ("Total"). InnerHTML;
And then, your GameTimer ()
function just keeps seeing the old value of totalDiv
so that the second counter ever Will not even increase.
You may want to change your code to re-examine the value of totalDiv
on each ticker of the timer:
Function GameTimer ( ) {Var minutes = Math.round ((sec - 30) / 60); // This does not save var seconds = seconds% 120; // more meaning .. var totalDiv = document.getElementById ("Total"). InnerHTML; Document.getElementById ('TimerID'). InnerHTML = Balance Seacand; Var totalDiv = document.getElementById ("Total"). InnerHTML; // ...
This shows a working version (based on your sample code, based on the modifications, based on my understanding of what you are doing )
And one more thing is not correct ..
seconds + = 30; If (second == 0) {// it will not be until unless before seconds-30. $ .mobile.changePage ("index.html # youlost", {Infection: "SlideUp"}); ClearInterval (countdownTimer); }
Comments
Post a Comment