Get Programming with JavaScript - Listing 12.02
Listing 12.02 - Guess the number - the else clause
var secret = 8;
var guess = function (userNumber) {
if (userNumber === secret) {
console.log("Well done!");
} else {
console.log("Unlucky, try again.");
}
};
Further Adventures
Listing 12.02 - Guess the number - the else clause - Tasks 2 & 4
- Change the condition in parentheses to check if the guess is not equal to the secret.
- Change the messages to fit the new condition.
var secret = 8;
var guess = function (userNumber) {
if (userNumber !== secret) {
console.log("Unlucky, try again.");
} else {
console.log("Well done!");
}
};