Magic 8 Ball project - switch keyword

https://www.codecademy.com/courses/introduction-to-javascript/projects/magic-eight-ball-1

I am having trouble with the Magic 8 Ball task. Having watched the video I am still not sure why my code is throwing an error :

let 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('Cannot predict now') break; case 4: eightBall('Do not count on it') break; case 5: eightBall('My sources say no') break; case 6: eightBall('Outlook not so good') break; case 7: eightBall('Signs point to yes') } console.log(`${eightBall}`)

eightBall is a variable, and values are supposed to be assigned to this variable.

eightBall is declared and initialized as an empty string "" i.e. initially, an empty string has been assigned to this variable.

In your cases, you want to assign new values to the eightBall variable. The correct syntax for assigning values is to use the = operator.
The syntax you are attempting to use is for when we want to call functions with some arguments. eightBall is not a function. It is a variable.

// You wrote:
eightBall('It is certain')

// It should be:
eightBall = 'It is certain'

and so on for the rest of the cases as well.

1 Like