Skip to main content
Caden5E78
Participant
December 31, 2020
Answered

Error: Syntax Error: Unexpected token else

  • December 31, 2020
  • 1 reply
  • 8515 views

Hello! I'm brand new to Adobe After Effects and just pasted in some code for a timer, but I'm getting a syntax error on line 1. I don't know much about codeing so I was hoping sombody smarter than me might know. Here's the code:

 

rate = 1;
clockStart = 0;
function padZero(n){
if (n < 10) return "0" + n else return "" + n
}
clockTime = clockStart + rate*(time - inPoint);
if (clockTime < 0){
sign = "-";
clockTime = -clockTime;
}else{
sign = "";
}
t = Math.floor(clockTime);
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
ms = clockTime.toFixed(3).substr(-3);
sign + padZero(min) + ":" + padZero(sec)

This topic has been closed for replies.
Correct answer Dan Ebberts

Try replacing this line:

if (n < 10) return "0" + n else return "" + n

with this:

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

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
December 31, 2020

Try replacing this line:

if (n < 10) return "0" + n else return "" + n

with this:

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

Caden5E78
Caden5E78Author
Participant
December 31, 2020

Thanks a bunch! that worked!

Participant
August 31, 2022

Happened. Thank you. Everything is working.