lightweight
lightweight

Reputation: 3337

var results in the function as string and not the result

I have a function that looks like this but for some reason it keeps returning the actual function in text then the result....how do I get it to return the result from the if statement and not the whole function as text?

    var xLbl = function () {

        if (yAxistm.tm === 'yr') {

            return "Year";

        } else if (yAxistm.tm === 'qtr') {

            return "Quarter";

        } else if (yAxistm.tm === 'mth') {

            return "Month";

        };

    };

    console.log("xLable: ", xLbl);

result:

xLable:  function () {

            if (yAxistm.tm === 'yr') {

                return "Year";

            } else if (yAxistm.tm === 'qtr') {

                return "Quarter";

            } else…

Upvotes: 0

Views: 51

Answers (4)

Tom O.
Tom O.

Reputation: 5941

You need to include the open and close parenthesis "()" after you type name of the function. console.log("xLable: ", xLbl());

This page explains everything

Upvotes: 1

Andrés Andrade
Andrés Andrade

Reputation: 2223

You need to call the function:

console.log("xLable: ", xLbl());

Upvotes: 0

Fueled By Coffee
Fueled By Coffee

Reputation: 2559

You're trying to print out the function definition..

You need to invoke the function

console.log("xLabel: ", xLbl());

Upvotes: 0

Bastiaanus
Bastiaanus

Reputation: 357

You are logging the value of xLbl which is a function. What you are trying to do is call the function. It should look like this console.log("xLabel: ", xLbl());.

Upvotes: 0

Related Questions