Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Review Creating and Naming Variables

Nurbek Ismailov
Nurbek Ismailov
2,068 Points

why var timeRemaining (); is wrong? how to fix it?


1 Answer

Kody Bentley
Kody Bentley
4,411 Points


Well I'm no expert but from what I know when adding parenthesis like timeRemaining(); you are typically telling JS that timeRemaining is a function. The correct syntax for a variable would be var timeRemaining = something;.

Now if you wanted you could have the variable timeRemaining equal a function in itself such as:

var timeRemaining = function() { //Whatever you want the function to do here }

Then instead of calling the function normally in your code like timeRemaining(); you can simply refer to the function by its variable name which would just be timeRemaining;

This is the best I could explain what I believe you were asking. If anyone else has a better answer or can explain it better please do so.

Thanks and happy coding!

Tushar Singh
Tushar Singh
Courses Plus Student 8,692 Points

Well as kody pointed out, you are basically mixing two things.

For now, lets not concentrate on storing a function in a variable. You will learn about it later.

var timeRemaining = function() { //Whatever you want the function to do here };

So. basically you define a variable by ignoring the parenthesis.

var timeRemaining = anyValue;

Now coming to the function part lets just say I have a function called "function1", I would call this function or you can say ask the program to run this function by


now the question is ---var timeRemaining = function() { //Whatever you want the function to do here }; What does this statement do? it basically stores your function in a variable and As I said ignore this for now, you will learn all about it later.