I'm doing a tutorial on code academy and I'm getting an error here saying "It looks like your function doesn't return 'Alas you do not qualify for a credit card. Capitalism is cruel like that.' when the income argument is 75." But that string is returned in the console (twice for some reason). I put it on their forum but I haven't got any response, anyone here got any suggestions?
var creditCheck = function(income) {
if (income >= 100){
return console.log("You earn a lot of money! You qualify for a credit card.");}
else {
return console.log("Alas you do not qualify for a credit card. Capitalism is cruel like that.");}
};
creditCheck (75);
-
1Do you want to log or return the message ?thiago.lenz– thiago.lenz2014年01月09日 12:10:19 +00:00Commented Jan 9, 2014 at 12:10
4 Answers 4
At a guess, you should be returning the string, not returning console.log("...");
I.e.
var creditCheck = function(income) {
if (income >= 100){
return "You earn a lot of money! You qualify for a credit card.";
} else {
return "Alas you do not qualify for a credit card. Capitalism is cruel like that.";
}
};
Comments
The problem is that you are not returning the string, you are returning the result of console.log(). Try this instead:
var creditCheck = function(income) {
if (income >= 100){
return "You earn a lot of money! You qualify for a credit card.";
}
else {
return "Alas you do not qualify for a credit card. Capitalism is cruel like that.";
};
And for completeness, the reason it logs twice is because you are manually calling the function in your code, and then Codecademy will becalling it too. So you don't need to include the function call yourself! The code here will not log anything, because that part has been removed.
1 Comment
It's either this
var creditCheck = function(income) {
if (income >= 100){
return "You earn a lot of money! You qualify for a credit card.";}
else {
return "Alas you do not qualify for a credit card. Capitalism is cruel like that.";}
};
creditCheck (75);
OR
var creditCheck = function(income) {
if (income >= 100){
console.log("You earn a lot of money! You qualify for a credit card.");}
else {
console.log("Alas you do not qualify for a credit card. Capitalism is cruel like that.");}
};
creditCheck (75);
Comments
remove console.log and then check for return value