This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Introduction to Functions in JS Forum

View Course » View Exercise

734 points
Ffb583464a17a2e654e34ec8ace0842e?s=140&d=retro
Submitted by
betaPlayer05434
almost 4 years ago

Problems with Exercises 3.11 and 3.12

In exercise 3.11 I input the following code:

var nameString = function (name) {
return "Hi, I am" + " " + name;
};

var myName = nameString(Fred);
console.log(myName);

The console returns, ReferenceError: Fred is not defined, but the green box at the bottom appears and lets me start the next lesson rather than showing me an error.

In exercise 3.12 I input the following code:

// Write your function below.
// Don't forget to call your function!
creditCheck = function (income) {
if (income >= 100);

return "You earn a lot of money! You qualify for a credit card.";
} else if (income < 100);
{ return "Alas you do not qualify for a credit card. Capitalism is cruel like that.";

};
creditCheck(75);

On line 6, the editor isn't expecting "else" of "else if" but I can't figure out how else to write the code.

I'm at a loss and don't know where to go to troubleshoot this. I've tried going through the previous exercises again thinking I forgot something but it doesn't help.

Thanks.


1 vote

permalink

Fred is a string and so should be in quotes.

if (income >= 100); Never put a semicolon at the end of an if statement. Replace the semicolon with an opening curly brackets. You'll need a corresponding closing brackets as well near where you call the function.

623 points
519ae98de89dff79370009d8_443080457
Submitted by
Neil
almost 4 years ago


1 vote

permalink

// Write your function below.
// Don't forget to call your function!
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);

290 points
52aacfd09c4e9dd778001418_529552166
Submitted by
Colin
almost 4 years ago

1 Comment

Ffb583464a17a2e654e34ec8ace0842e?s=140&d=retro betaPlayer05434 almost 4 years ago

Thanks for the quick assistance, Neil and Colin.