Magic ball

//user name

let userName=‘Chantelle’;

//to check whether user has provided their name or not

userName ? console.log(Hello ${userName}):

console.log(‘Hello!’);

//magic ball question

let userQuestion=‘are you ok’;

console.log(userQuestion);

//statement to generate random numner

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

let eightBall=randomNumber;

//switch cases

switch(randomNumber)

{

case(0):

console.log(‘It is certain’);

break;

case(1):

console.log(‘It is decidedly 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;

}

//logging random number

console.log(eightBall);

Hey there!

Do you have a specific question, or just sharing a project?
Currently you have an error in your first console.log(). Take a look at what your trying to print.


On a side note, in the future when you post please look at formatting your code. This preserves indentation, allows you to post HTML, and improves your codes readability.
To format it, simply press this button:

Then copy/paste your code between the backticks:

Hello. I can’t get my code to work and I am completely bamboozled. Could someone take a look? I’m sure it’s going to be blindingly obvious. Thank you.

let userName = 'Bob';
userName ? console.log('Hello, ${userName}!') : console.log('Hello!');

const userQuestion = 'Will I have a good day today?';
console.log=('You asked: ${userQuestion}');

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

let eightBall='';

switch (randomNumber) {
  case 0:
  eightBall='It is certain';
  break;
  case 1:
  eightBall='It is decidely 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';
  break;
}

console.log(`The eight ball answered: ${eightBall}`); 

There’s an extra ‘=’-sign around line 5 or so, after the console.log command.

Also note: you should use backticks (`) when logging using template literals. I mean, I think now when you run your code, the output would be like ‘Hello, ${username}’ and not ‘Hello Bob’.

2 Likes