0

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);
1
  • 1
    Do you want to log or return the message ? Commented Jan 9, 2014 at 12:10

4 Answers 4

3

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.";
  }
};
Sign up to request clarification or add additional context in comments.

Comments

2

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

Glad to see someone explaining the problem and solution :)
1

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

0

remove console.log and then check for return value

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.