/    Sign up×
Community /Pin to ProfileBookmark

30 Minute Countdown Clock

I have created a 30:00 Countdown Clock but when it gets to 9 seconds in
the seconds field it shows a 9 instead of 09

Example

This is what I get: 29:9

This is what I need: 29:09

Not sure how to do it, I am new to working with JavaScript

<form name=”counter”><input type=”text” size=”8″
name=”d2″></form>

<script>
<!–
//
var minutes=30
var seconds=00

document.counter.d2.value=’30:00′

function display(){
if (seconds<=0){
minutes-=1
seconds+=59
}
if (minutes<=-1){
minutes==1
seconds=0

}
else
seconds-=1
document.counter.d2.value=minutes+”:”+seconds
setTimeout(“display()”,1000)
}
display()
–>
</script>

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 14.2010 — [CODE]if( seconds < 10 ) { seconds = '0'+seconds ;}[/CODE]
Copy linkTweet thisAlerts:
@rononauthorSep 14.2010 — Thanks Fang, but as I said I am very new to JavaScript, and I need to see that line of code placed inside the script I have because I do not know where to place it to get it to work. Thanks.
Copy linkTweet thisAlerts:
@FangSep 14.2010 — Just before it is displayed
Copy linkTweet thisAlerts:
@rononauthorSep 14.2010 — this is where I put it and it does not work

<script>

<!--

//

var minutes=30

var seconds=00

document.counter.d2.value='30:00'

function display(){

if (seconds<=0){

minutes-=1

seconds+=59

}

if (minutes<=-1){

minutes==1

seconds=0

}

if( seconds < 10 ) { seconds = '0'+seconds ;}

else

seconds-=1

document.counter.d2.value=minutes+":"+seconds

setTimeout("display()",1000)

}



display()

-->

</script>


Please post the code with it in the correct spot. thanks.
Copy linkTweet thisAlerts:
@rononauthorSep 15.2010 — Does anyone know how to make this work?
Copy linkTweet thisAlerts:
@FangSep 15.2010 — [CODE]else
seconds-=1
[COLOR="Green"]// code goes here[/COLOR]
document.counter.d2.value=minutes+":"+seconds [COLOR="Green"]// display result [/COLOR]
setTimeout("display()",1000)
}
[/CODE]
Copy linkTweet thisAlerts:
@rononauthorSep 16.2010 — Thanks, that worked!
×

Success!

Help @ronon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...