Ask coding questions

← Back to all posts
Console.log problem
seth08g (1)

I used console.log for something and it keeps saying unexpected identifier under some words that I'm trying to input into the console. Here is what it looks like...

function questionNumberThree() {
switch(true) {
console.log('CLASH: Here I will show you Magica! We should not be in this old shack all day anyway.')
}
}
Some words are pointed and it says 'Unexpected Identifiers' please help!

Answered by OldWizard209 (1615) [earned 5 cycles]
View Answer
Comments
hotnewtop
OldWizard209 (1615)

Hey. You have a MASSIVE ISSUE in your code. Firstly, Switch statements don't work like if statements. This is the syntax of switch statements:

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}

Ad instead of using :, you have used a ===, which is used in conditionals. And secondly, the expression value you have put is true, and later you are using player as a case. Rather, you have to do this:

let player = prompt('Do you want to play MagicKombat?')

let answers = ['yes', 'no', 'history', 'attack']

function playMagicKombat() {
  
  switch(player) {
    
    
    case 'no':
        console.log('Ok your loss')
        process.exit(0);
        break
    case 'yes':
        console.log('Ok lets begin our journey!')
        console.log('You wake up to a wizard standing infront of you, he has a long white beard.')
        console.log('YOU: Where am I you ask in confusion')
        console.log('WIZARD: In Magica of course where else would you be?')
        console.log('YOU: What is Magica and who are you??')
        break

  }
} 

playMagicKombat()




function questionNumberTwo() {
  var questionTwo = prompt('Do you ask the wizard about the Magica and what it is and its history by typing history. or do you decide to attack the wizard by typing attack.')

  switch(questionTwo) {

    case 'history':
        console.log('WIZARD: Magica was once filled with darkness we call the shadows. Back then I was young and a powerfull mage and was able to defeat the shadows and the person producing them the lord of darkness but I am no longer in my glory days and turns out I did not fully kill him and we need someone new to save Magica so thats why we chose you. Oh I am Clash by the way, Clash the wizard!')
        console.log('You have befriended Clash the wizard.')
        break
    case questionTwo === 'attack':
        console.log('You sprint at the wizard but the wizard saw the future and knew it was coming and quickly decapitated you, GAME OVER.')
        process.exit(0);
  }
}

questionNumberTwo()

This is your fixed code, hope i helped.

seth08g (1)

@OldWizard209 Thanks this REALLY helped I am a beginner so that is why most my code is not very good

OldWizard209 (1615)

@seth08g no prob. would you mind marking the answer as correct?

OldWizard209 (1615)

no need to apologize lol. we are all good :P @seth08g

seth08g (1)

Please anyone help it will be much appreciated.
Thanks