6 Replies Latest reply on Nov 29, 2018 10:23 PM by sudeshprathapv

# Creating a Sports Scoreboard Timer in AE

I have ventured Far and Wide to find the problem with an expression i am using. I am creating a Scoreboard timer for a Soccer game recently recorded. However i have met numerous problems with it. once i get to > 10 mins there is a zero constantly in the minutes column. i see the issues but im not sure what expression i could use to right the wrong. Any help would be greatly appreciated.

sec = Math.floor(time%60);

min = Math.floor(time/60);

if(sec<10)

{"0" + min +":0" + sec;}

else

{"0" + min +":" + sec;}

Thank you

• ###### 1. Re: Creating a Sports Scoreboard Timer in AE

Try it this way:

function padZero(n){

return (n < 10 ? "0" : "") + n;

}

sec = Math.floor(time%60);

min = Math.floor(time/60);

padZero(min) + ":" + padZero(sec)

Dan

• ###### 2. Re: Creating a Sports Scoreboard Timer in AE

for people who wanna understand the above expression: (still I couldnt understand how you used the a

The padzero( ) function makes the text a fixed width, padding on the left with zeros if necessary.

This function has two parameters:

text – the original text.

width – desired number of characters.

Description

This function makes the text a fixed width. If the text is shorter than the specified width, it is padded with 0s on the left (i.e. the text is right justified). If it is longer than the specified width, it is cut off on the left.

``padzero("abcdxyz",12) ☞ 00000abcdxyz padzero("85.22",7)    ☞ 0085.22 ``

`source: padzero( function `

below expression will work?

sec = Math.floor(time%60);

min=Math.floor(time/60)

M=padZero("min",3);

S=padZero("sec",3);

M+":"+S

• ###### 3. Re: Creating a Sports Scoreboard Timer in AE

`can you explain this section?`

`function padZero(n){  return (n < 10 ? "0" : "") + n;`

it it was like below, I would have understood.

function padZero(n){
return (n < 10 ? "0") + n;

why do we need to add --->  :""    <--- in the expression.
I don't understand that part alone

• ###### 4. Re: Creating a Sports Scoreboard Timer in AE

function padZero(n){
return (n < 10 ? "0" : "") + n;

Result at 5 sec ==> 00:05

Result at 1:30 min ==> 01:30

function padZero(n){
return (n < 10 ? "Y" : "N") + n;

Result at 5 sec ==> 00:Y5

Result at 1:30 min ==> 01:N30

I think I understood.