I am doing the Codecademy JS training as a review for a course I'm taking soon. I hit the creditCheck function exercise which basically just wants a function that evaluates an integer and returns one value for above 100, and one for below. I thought that the code below should work, but it is running without being called. Why is this happening?
creditCheck = function(income)
{
income *= 1; // one way to convert the variable income into a number.
if (income>100)
{
console.log("You earn a lot of money! You qualify for a credit card.");
return true; // this is an actual return value, console.log() always returns "undefined"
}
else
{
console.log("Alas you do not qualify for a credit card. Capitalism is cruel like that.");
return false;
}
};
console.log("If the log is executing in the function def then this should print second. Otherwise it's probably being executed by the coding script itself.\n\n")
RESOLUTION (Maybe): So I just tested the script in a console off of the Codecademy site. It doesn't self execute anywhere except on that site. This leads me to believe that there is something funky going on with that page.
More Resolution (also Maybe): I also added that last line above to test when the function was being called. Since it's the last line in the program, my assumption is that if the execution is in the function body itself, that that last line would print last. This leads me to believe that the grading script is calling the function on its own accord which means that when I add in the actual function calls, it's messing it up.
You have to call the function you have defined.
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(111);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With