So here’s the Magic Eight Ball project where you need to define 2 variables and assign them to the value of empty strings. It’s said that the action is made for the user’s input. But the third time they ask you to do the same whereas there’s no need for the user’s input. Here’s the code:
let userName=’’;
userName? console.log('Hello, ’ + userName + ‘!’) : console.log(‘Hello!’);
let userQuestion=’’;
console.log(userQuestion);
const randomNumber=Math.floor(Math.random() * 8);
let eightBall=’’;
switch (randomNumber) {
case 0:
eightBall=‘It is certain’;
break;
case 1:
eightBall=‘It is decidedly so’;
break;
case 2:
eightBall=‘Reply hazy try again’;
break;
case 3:
eightBall=‘Do not count on it’;
break;
case 4:
eightBall=‘My sources say no’;
break;
case 5:
eightBall=‘Outlook not so good’;
break;
case 6:
eightBall=‘Signs point to yes’;
break;
default:
eightBall=‘Absolutely yes GIRL!’;
break;
}
console.log(Magic Eight Ball says: ${eightBall}
);
The question is Why do you have to assign empty strings to variables when you don’t want the user to input anything? cuz it works just the same without the assignment.