Empty strings

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=’’;

const randomNumber=Math.floor(Math.random() * 8);

let eightBall=’’;

switch (randomNumber) {
case 0:
eightBall=‘It is certain’;
case 1:
eightBall=‘It is decidedly so’;
case 2:
eightBall=‘Reply hazy try again’;
case 3:
eightBall=‘Do not count on it’;
case 4:
eightBall=‘My sources say no’;
case 5:
eightBall=‘Outlook not so good’;
case 6:
eightBall=‘Signs point to yes’;
eightBall=‘Absolutely yes GIRL!’;

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.

1 Like

@digital3070518405 welcome to the forums!
I think with the question you are asking, it is just protocol, so that, when developing with other developers, it is easier for the code to be read.
I hope this helps!
Happy coding!

1 Like

Because it’s like pattern for conditionals snip code.
You can add your code.
Like “let UserName=digital3070518405;”, nobody forbids you this.
Or you may wrap all this code in function and later use it.
You learn to write correct code.