Advertisement
makispaiktis

Codecademy - 9th Exercise (EightBall)

Oct 1st, 2019 (edited)
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let userName = "";
  2. // If user gives his name, then userName variable
  3. // will be set equal to this name
  4. // I will create another variable in the case the
  5. // user wants to change this name
  6. let nameWritten = "Thomas";
  7. userName = nameWritten || "";
  8. // If the variable "nameWritten" is not empty, then userName will be set equal to the given nameWritten variable, otherwise it will be the string ""
  9. console.log(`Hello ${userName}!`);
  10. console.log();
  11.  
  12. let userQuestion = "What's the time?";
  13. console.log(`${userName} asks this question: ${userQuestion}`);
  14.  
  15. // Generating a random number between 0 and 7
  16. let randomNumber = Math.floor(Math.random() * 8);
  17. let eightBall = "";
  18.  
  19. switch(randomNumber){
  20.    
  21.   case 0:
  22.     eightBall = "It is certain!";
  23.     break;
  24.   case 1:
  25.     eightBall = "It is decidedly so!";
  26.     break;
  27.   case 2:
  28.     eightBall = "Reply hazy try again!";
  29.     break;
  30.   case 3:
  31.     eightBall = "Cannot predict now...";
  32.     break;
  33.   case 4:
  34.     eightBall = "Do not count on it...";
  35.     break;
  36.   case 5:
  37.     eightBall = "My sources say no...";
  38.     break;
  39.   case 6:
  40.     eightBall = "Outlook not so good...";
  41.     break;
  42.   case 7:
  43.     eightBall = "Signs point to yes!";
  44.     break;
  45.   default:
  46.     eightBall = "It is impossible to go in case 'default'.";
  47.     break;
  48. }
  49.  
  50. // EightBall answers
  51. console.log(`Eightball answers this: ${eightBall} (${randomNumber})`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement