Reputation: 3337
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
Reputation: 5941
You need to include the open and close parenthesis "()" after you type name of the function.
console.log("xLable: ", xLbl());
Upvotes: 1
Reputation: 2223
You need to call the function:
console.log("xLable: ", xLbl());
Upvotes: 0
Reputation: 2559
You're trying to print out the function definition..
You need to invoke the function
console.log("xLabel: ", xLbl());
Upvotes: 0
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