I am working on the Magic Eightball Project in the Javascript course. The code I’ve written appears to be working correctly, as it generates a different response each time; however, I am certainly missing some of the steps outlined by Codecademy.
Is my code actually working, or is something unintended happening?
let userName = "Audrey";
userName ? console.log(`Hello, ${userName}!`) : console.log("Hello!");
const userQuestion = "Will I be rich?";
console.log(`${userName} asked, ${userQuestion}.`);
let randomNumber = Math.floor(Math.random() * 8);
switch (randomNumber) {
case 0:
console.log("It is certain");
break;
case 1:
console.log("It is decidely so");
break;
case 2:
console.log("Reply hazy try again");
break;
case 3:
console.log("Cannot predict now");
break;
case 4:
console.log("Do not count on it");
break;
case 5:
console.log("My sources say no");
break;
case 6:
console.log("Outlook not so good");
break;
case 7:
console.log("Signs point to yes");
break;
}
You code looks fine and runs as expected. If this is a free flow project, just check all the boxes and you’re done. Are there other ways to do this? Certainly, but that shouldn’t matter so long as your code works and there are no errors. You can always come back to it and try out different approaches when you have practice time set aside.
If this was a function, then the console.log() would become return, and all the break keywords could be removed.