Hello. I was just trying to working on a eight ball project and felt I finished it but never got it to work properly. Random number is generated through .math which is 1 or 2 an then multiplied by 8? When I’d think it be a maximum of 8. Then the empty eightBall be givin the random number that was generated which is then switched through the values which have a corresponding string value which is then displayed with console log. Only the string values for the valued numbers doesn’t show at the end of the code it seams.
I just want to know why it doesnt show anything for the new eightball value. it shows the random number. Please can someone help I am new and this is one of my first projects with a lot to take in.
I would really appreciate it.
let randomNumber = Math.floor(Math.random() * 8);
console.log(`${randomNumber}`);
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 = 'It is certain';
break;
}
console.log(`The computer predicts
${eightBall} `);
console.log(eightBall);
//the code outputs
Hello Tom
Tom has asked: Can you answer the quesiton?
4
The computer predicts
The code outputs