switch (randomNumber){
case 1: eightBalls=‘I am super’;break;
case 2: eightBalls=‘Army calling’;break;
case 3: eightBalls=‘Success loading’;break;
case 4: eightBalls=‘Look ahead’;break;
case 5: eightBalls=‘ad astra per aspera’;break;
case 6: eightBalls=‘Ubuntu’;break;
case 7: eightBalls=‘gameplan is to achieve’;break;
}
I need help in converting the above switch statement to if else /else if statements. below is the link to the codecademy eightballs project
First off, put your code in line with the instructions…
* 'It is certain'
* 'It is decidedly so'
* 'Reply hazy try again'
* 'Cannot predict now'
* 'Do not count on it'
* 'My sources say no'
* 'Outlook not so good'
* 'Signs point to yes'
and the variable is, eightBall
.
Consider,
switch (expression) {
case 1:
action; break;
case 2:
action; break;
default:
action;
}
can be equated to,
if (expression === 1) {
// action
} else if (expression === 2) {
// action
} else {
// action
}