8 Ball Game


#1

how to prompt browser to ask no. and result on basis of input?

var myNumber = prompt('Choose number');
var eightBall =' ' ;

switch(myNumber) {
  case 0:
    eightBall = 'It is certain';
    break;
  case 1:
    eightBall = 'It is decidedly so';
    break;
  case 2:
    eightBall = 'Cannot predict now';
    break;
  case 3:
    eightBall = 'Don\'t count on it';
    break;
  case 4:
    eightBall = 'My sources say no';
    break;
  case 5:
    eightBall = 'Outlook not so good';
    break;
  case 6:
    eightBall = 'Signs point to yes';
    break;
  case 7:
    eightBall = 'You are in grave danger';
    break;
  default:
    eightBall = 'Reply hazy try again';
   break;
    
 }
console.log('The eight ball answered: ' + eightBall);

#2

prompt() stores the result as string, while the cases of your switch statements are integers. That is a problem you need to overcome.


#3

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