Error: Syntax Error: Unexpected token else

New Here ,
Dec 31, 2020 Dec 31, 2020

Copy link to clipboard

Copied

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)

TOPICS
Error or problem , Expressions

Views

5.0K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 31, 2020 Dec 31, 2020

Try replacing this line:

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

with this:

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

Likes

Translate

Translate
Community Expert ,
Dec 31, 2020 Dec 31, 2020

Copy link to clipboard

Copied

Try replacing this line:

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

with this:

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 31, 2020 Dec 31, 2020

Copy link to clipboard

Copied

Thanks a bunch! that worked!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

Happened. Thank you. Everything is working.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2022 Aug 31, 2022

Copy link to clipboard

Copied

LATEST

Happened. Thank you. Everything is working.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines