javascript - Self-Executing JS Function -
i doing codecademy js training review course i'm taking soon. hit creditcheck function exercise wants function evaluates integer , returns 1 value above 100, , 1 below. thought code below should work, running without being called. why happening?
creditcheck = function(income) { income *= 1; // 1 way convert variable income number. if (income>100) { console.log("you earn lot of money! qualify credit card."); return true; // actual return value, console.log() returns "undefined" } else { console.log("alas not qualify credit card. capitalism cruel that."); return false; } }; console.log("if log executing in function def should print second. otherwise it's being executed coding script itself.\n\n")
resolution (maybe): tested script in console off of codecademy site. doesn't self execute anywhere except on site. leads me believe there funky going on page.
more resolution (also maybe): added last line above test when function being called. since it's last line in program, assumption if execution in function body itself, that last line print last. leads me believe grading script calling function on own accord means when add in actual function calls, it's messing up.
you have call function have defined.
var creditcheck = function(income) { if (income>100) { return(console.log("you earn lot of money! qualify credit card.")); } else { return(console.log("alas not qualify credit card. capitalism cruel that.")); } }; creditcheck(111);
Comments
Post a Comment