Magic 8 Ball

I’ve done this exercise a few times just to make sure I understand the logic.
One thing I need some clarification on however, is when we set the variable eightBall to an empty string.

let eightBall = ‘’’’;

Does it really matter in this case? If a number is inserted, the program still seems to execute the same. I appreciate any insight into this.

Thank You!!!

@ajax7383493197 The let eightBall = "" is just there as protocol, because it means that if anyone else reads your code, it will be easier for them to understand it.

Thank you. I just ran the code without, and it still works. So basically, it serves no purpose other than an “indicator”? I thought this was actually declaring the eightBall variable?

Is eightBall not a variable??

Thanks again.

@ajax7383493197 The code block let eightBall = "" does declare the variable, but you could just as easily put the let within your code. For example:

randomNumber = 0
if (randomNumber == 0) {
let eightBall = "string";

would provide the same result as

randomNumber = 0
let eightBall = ""
if (randomNumber == 0) {
eightBall = "string";

However, the latter is more readable for other people. I hope this helps!
Happy coding!

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.