My code is not working in 'Magic Eight Ball'

Hello everyone,
I am stuck in the ‘Magic Eight Ball’ exercise. My code somehow doesn’t work though I compared it with the video which is provided in the ‘get Unstuck’.

let userName = 'Jane';
userName ? console.log(`Hello,${userName}!`):console.log('Hello!');
const userQuestion = 'Will i become a web developer?';
console.log(`${userName} asked '${userQuestion}'`);

let randomNumber = Math.floor(Math.random()*8);
console.log(randomNumber);

let eightBall = '';

swith(randomNumber) {
  case 0:
  eightBall='Signs point to yes';
  break;  

  case 1:
  eightBall='It is certain';
  break;
  case 2:
  eightBall='It is decidedly so';
  break;

    case 3:
  eightBall='Reply hazy try again';
  break;

    case 4:
  eightBall='Cannot predict now';
  break;

    case 5:
  eightBall='Do not count on it';
  break;

    case 6:
  eightBall='My sources say no';
  break;

   case 7:
  eightBall='My sources say no';
  break;   
}
console.log(`The magic eight ball says ${eightBall}`);

the runtime error says:

/home/ccuser/workspace/learn-javascript-U2P1/main.js:10
swith(randomNumber) {
                    ^

SyntaxError: Unexpected token '{'
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
    at internal/main/run_main_module.js:17:47

could anyone please kindly help to take a look. thank you very much!!:slight_smile:

Hey, @linglin7144518330 welcome to the forums.

You misspelled switch.

Hey, @not-ethan thank you very much for such a quick reply. Cool!!
problem solved. what a stupid mistake was that. :rofl: :rofl:

2 Likes