# Control flow / Control de flujo (if...else/switch...case)

Mon Oct 11 2021 12:26:57 GMT+0000 (Coordinated Universal Time)

```let userName = '';
/* Con nombre o sin nombre */
/* Se guarda la pregunta */
let userQuestion = 'Is this true?';
/* Se muestra la pregunta */
/* Se genera un número aleatorio entre 0-8 */
randomNumber = Math.floor(Math.random() * 8);
/* Se guarda la respuesta en una variable */
let eightBall = '';
/* Se guardan distintas respuestas para el número que toque */
// takes in randomNumber, then eightBall = 'Reply'
// you can use if/else or switch;
// If the randomNumber is 0, then save an answer to the eightBall variable; if randomNumber is 1, then save the next answer, and so on.
/* Se utiliza switch */
/*
switch (randomNumber) {
case 0:
eightBall = 'It is certain';
break;
case 1:
eightBall = 'It is decidedly so';
break;
case 3:
eightBall = 'Reply hazy try again';
break;
case 4:
eightBall = 'Cannot predict now';
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;
}
*/
/* Se utiliza if */
if (randomNumber === 0) {
eightBall = 'It is certain';
}
if (randomNumber === 1) {
eightBall = 'It is decidedly so';
}
if (randomNumber === 2) {
eightBall = 'Reply hazy try again';
}
if (randomNumber === 3) {
eightBall = 'Cannot predict now';
}
if (randomNumber === 4) {
eightBall = 'Do not count on it';
}
if (randomNumber === 5) {
eightBall = 'My sources say no';
}
if (randomNumber === 6) {
eightBall = 'Outlook not so good';
}
if (randomNumber === 7) {
eightBall = 'Signs point to yes';
}
/* Se muestra */
console.log(eightBall);```
content_copyCOPY

Magic Eight Ball You’ve learned a powerful tool in JavaScript: control flow! It’s so powerful, in fact, that it can be used to tell someone’s fortune. In this project we will build the Magic Eight Ball using control flow in JavaScript. The user will be able to input a question, then our program will output a random fortune.