Get Programming with JavaScript - Listing 12.03
Listing 12.03 - Guess the number - using local scope
var getGuesser = function () {
var secret = 8;
return function (userNumber) {
if (userNumber === secret) {
console.log("Well done!");
} else {
console.log("Unlucky, try again.");
}
};
};
var guess = getGuesser();