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 = ‘Signs point to yes’;
break;
}
is causing this syntax error:
/home/ccuser/workspace/learn-javascript-U2P1/main.js:43
});
^
SyntaxError: Unexpected token }
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
I tried your switch and it did not raise any errors (as was my expectation, the code looks fine).
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 = `Signs point to yes`;
break;
}
The might be somewhere else in your code. Please post the missing bits.
I think you are missing the default part of your case-switch statement. It looks good other than that.
mtf23h
I tried your switch and it did not raise any errors (as was my expectation, the code looks fine).
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 = `Signs point to yes`;
break;
//Add the following:
default:
//Do some code here
}
The default case is not needed since all lthe cases are program generated. A default is only necessary when there is chance that some data will get into the switch and not match any cases. That is not the case here.