What's wrong? What am I missing?

js

#1
              switch(crown3){
                    case"FIREBALL":
                        alert("Wow! you beat me.... Have fun in the full game. Download it on iOS or Android");
                        break;
                        case"PEKKA":
                             alert("Wow! you beat me.... Have fun in the full game. Download it on iOS or Android");
                        break;
                        case"BALLOON":
                             alert("Wow! you beat me.... Have fun in the full game. Download it on iOS or Android");
                        break;
                        default:
                        alert("What card is that?");
                }
     } else {
        alert("You can't quit in this battle! HAHAHA!!!");
    }
    break;
    case"ELITE BARBARIANS":
        var crown4 = confirm("Are you sure you want to play that card?");
        if(crown4) {
            alert("You took down the the Kings Tower! You won!");
            } else {
                    alert("You can't quit yet");
            }
    break;
    default:
        alert("What card is that?");
    }
alert("Now go buy a Nintendo Switch with Legend of Zelda: Breath of the Wild");

the problem is somewhere in here

                    case"FIREBALL":
                        alert("Wow! you beat me.... Have fun in the full game. Download it on iOS or Android");
                        break;
                        case"PEKKA":
                             alert("Wow! you beat me.... Have fun in the full game. Download it on iOS or Android");
                        break;
                        case"BALLOON":
                             alert("Wow! you beat me.... Have fun in the full game. Download it on iOS or Android");
                        break;
                        default:
                        alert("What card is that?");
                }
     } else {
        alert("You can't quit in this battle! HAHAHA!!!");
    }

#2

Not enough code to judge what the exact error is. Can we see it from start to finish, please?


#3

for that, a link would be most helpfuliful

https://www.codecademy.com/SuperN3rd02/codebits/Pdy6cc

if no link it wanted, please read all 193 lines of JS

alert("All answers must be typed. Please note that answers typed with CAPS LOCK on is optional.");
var clashRoyale = confirm("Welcome to the Arena, Challenger! To Enter the Full game, you must Beat me. The Creator.");
if (clashRoyale) {
    alert("Well then. Prepare for the Battle to start your Journey in the World of Clash Royale.");
} else {
    alert("Well then, if you don't want to fight, I won't fight");
}
if (clashRoyale === false) {
    alert("I lied... I WILL WIN!");
} else {
    alert("I will defeat you!");
}
alert("I , the Creator, Choose " + cardtype() + "!");
function cardtype() {
 return "Pekka";   
}
var ClashRoyale = prompt("The Creator played a Pekka. What will you play? a SKELETON ARMY, a MINION HORDE, or a GOLEM").toUpperCase();
switch(ClashRoyale){
    case 'SKELETON ARMY':
        var hit = confirm("Are you sure you want to play that card?");
        if(hit) {
            alert("The Pekka Dies.");
            } else {
                alert("You can't quit in this battle! HAHAHA!!!");
            }
            break;
    case 'MINION HORDE':
        var hit2 = confirm("Are you sure you want to play that card?");
        if(hit2) {
            alert("The Pekka dies");
        } else {
            alert("You can't quit in this battle! HAHAHA!!!");
        }
        break;
        case 'GOLEM':
            var hit3 = confirm("Are you sure you want to play that card?");
            if(hit3) {
                alert("The Golem distracts the Pekka and gives you time.");
            } else {
                alert("You can\'t quit in this battle! HAHAHA!!!You can't quit in this battle! HAHAHA!!!"); 
            }
            break;
            default:
            alert("You can\'t play that card");
}
alert("I Choose " + cardype() + "!")
function cardype() {
    return "Valkyrie";   
}
var hit1 = prompt("The Creator played a Valkyrie. What will you play? a MINION HORDE, a WIZARD, or BARBARIANS").toUpperCase();
    switch(hit1){
        case 'MINION HORDE':
            var hit4 = confirm("Are you sure you want to play that card?");
            if (hit4) {
                alert("The Valkyrie dies, and you deal 1000 damage to a crown tower");
            } else {
                alert("You can't quit in this battle! HAHAHA!!!");
            }
            break;
        case 'WIZARD':
            var hit5 = confirm("Are you sure you want to play that card?");
            if (hit5) {
                alert("You killed the Valkyrie!");
            } else {
                alert("You can't quit in this battle! HAHAHA!!!");
    }
    break;
    case 'BARBARIANS':
        var hit6 = confirm("Are you sure you want to play that card?");
        if(hit6) {
            alert("Both Troops die");
        } else {
            alert("You can't quit in this battle! HAHAHA!!!");
        }
    break;
    default:
    alert("What card is that?");
    }
    alert("I , the Creator, Choose " + cardtyp() + "!");
function cardtyp() {
 return "Fireball";   
}
    var Hit = prompt("The Creator played a Fireball. You can't counter that. What card do you want to play? ELITE BARBARIANS, a VALKYRIE, or FIRE SPIRITS").toUpperCase();
    switch(Hit){
        case 'ELITE BARBARIANS':
            var hit7 = confirm("Are you sure you want to play that card?");
            if(hit7) {
                alert("You take down one crown tower");
            } else {
                alert("You can't quit in this battle! HAHAHA!!!");
            }
            break;
            case 'VALKYRIE':
                var hit8 = confirm("Are you sure you want to play this card?");
                if(hit8) {
                    alert("You take down one crown tower, and deal 120 damage to the king tower");
                } else {
                    alert("You can't quit in this battle! HAHAHA!!!");
                }
                break;
                case 'FIRE SPIRITS':
                    var hit9 = confirm("Are you sure you want to play that card?");
                    if(hit9) {
                        alert("You deal 90 damage to one of the crown towers");
                    } else {
                        alert("You can't quit in this battle! HAHAHA!!!");
                    }
                    break;
                    default:
                    alert("What card is that?");
    }
    alert("The Creator took down your right tower.");
    alert("I Choose " + cardtye() + "!");
function cardtye() {
 return "Tombstone";   
}
    var card1 = prompt ("The Creator played a Tombstone card, it's easily countered but can be overwhelming. What do you want to play? A MINI PEKKA, a FIREBALL, or ARCHERS").toUpperCase();
    switch(card1){
        case 'MINI PEKKA':
            var hit10 = confirm("Are you sure you want to play that card?");
            if(hit10) {
                alert("You took down The Creators Left Tower.");
            } else {
                alert("You can't quit in this battle! HAHAHA!!!|");
            }
            break;
            case 'FIREBALL':
                var hit11 = confirm("Are you sure you want to play that card?");
                if (hit11) {
                    alert("You deal 2000 to The Creators King Tower");
                } else {
                    alert("You can't quit in this battle! HAHAHA!!!");
                }
                break;
                case 'ARCHERS':
                    var hit12 = confirm("Are you sure you want to play that card?");
                    if (hit12) {
                        alert("You deal 200 damage to the King tower.");
                    } else {
                        alert("You can't quit in this battle! HAHAHA!!!");
                    }
                    break;
                    default:
                    alert("What card is that?");
    }
alert("Overtime +60 seconds");
    alert("I Choose " + cardtpe() + "!");
function cardtpe() {
 return "Pekka";   
}
var overtime = prompt("You have to take down another Crown tower to beat The Creator. What do you play? a PEKKA, a  ROCKET, or ELITE BARBARIANS?").toUpperCase();
    switch(overtime){
        case "PEKKA":
            var crown1 = confirm("Are you sure you want to play that card?");
            if(crown1){
                alert("You take down The Creator's King Tower! You Won!");
            } else {
                alert("You can't quit in this battle! HAHAHA!!!");
            }
        break;
        case"ROCKET":
            var crown2 = confirm("Are you sure you want to play that card?");
            if(crown2){
                var crown3 = confirm("200 HP left on the King's Tower! another card and you can win! FIREBALL, PEKKA, or BALLOON?").
                switch(crown3){
                    case"FIREBALL":
                        alert("Wow! you beat me.... Have fun in the full game. Download it on iOS or Android");
                        break;
                        case"PEKKA":
                             alert("Wow! you beat me.... Have fun in the full game. Download it on iOS or Android");
                        break;
                        case"BALLOON":
                             alert("Wow! you beat me.... Have fun in the full game. Download it on iOS or Android");
                        break;
                        default:
                        alert("What card is that?");
                }
     } else {
        alert("You can't quit in this battle! HAHAHA!!!");
    }
    break;
    case"ELITE BARBARIANS":
        var crown4 = confirm("Are you sure you want to play that card?");
        if(crown4) {
            alert("You took down the the Kings Tower! You won!");
            } else {
                    alert("You can't quit yet");
            }
    break;
    default:
        alert("What card is that?");
    }
alert("Now go buy a Nintendo Switch with Legend of Zelda: Breath of the Wild");

#4

the reason I only gave you that snippet was because that’s where I was assuming the problem was, and where the error messages were appearing.


#5

The hope is that someone with the same interest as you in the game will weigh in with some advice. If this is code that you wrote then you should be able to find your problem. If not, then it will make a good project to practice your debugging skills.


#6

the thing is… it’s probably just a missing bracket somewhere around the first chunk of code I showed… if so I’m just gonna cry :sweat_smile:


#7

Errors can be in places other than where they raise an exception. In your case is it a SyntaxError during parsing, or a runtime error (exception)? What is the error message?


#8

Syntax errors really shouldn’t be much of a mystery, the error message should tell you all about what is going on, and if it still isn’t clear make a copy of the problematic part and start removing/simplifying things until you find the issue and then you might look up the language construct that you’re having trouble with <- that’s rather crude and in nearly every case you should be able to spot it immediately assuming a decent grasp of js syntax, but if you don’t you still should be able to make short work of it


#9

it says Expected '}' to match '{' from line 165 and instead saw 'case'. Missing semicolon. Expected '}' to match '{' from line 163 instead saw ':'.


#10

the problem comes in at the fact I’m embedding switch statements in if/else statements because the brackets of the if/else are trying to finish during the switch statements.


#11

Why would you add a switch without adding both {}'s? And if that’s the case then it’s trivially fixable even if you did make a typo or forgot when adding that. The switch is rather self-contained, it’s not going to mysteriously interact with what’s outside it

if (cond) {
  switch () {
  }
}

#12

yah it wasn’t this. it was the fact I forgot to change the confirm to prompt and finish writing the .toUpperCase()


#13

Again with the crude methods, you could cut out part of the code and see if it is valid by itself, and then check the surrounding code.

And if that still doesn’t make it manageable then perhaps there’s just far too much code in one place which needs to be broken out into functions


#14

Stuff like this is also incredibly easy to find by eyeballing

(Especially when doing the edit, and typically you’ll re-run the code or in some way validate the syntax every few edits anyway, so it should be immediately found anyway)

Here too,

            } else {
                alert("You can't quit in this battle! HAHAHA!!!");
    }

You shouldn’t even be able to introduce that in the code, you’re not blind-folded while typing


#15

I do check my code after every edit, because it’s running a TON of prompts and confirms as well as alerts do if the code 100% runs, there are no problems, if it stops half way through, or doesn’t run at all, then I know the code doesn’t work at all


#16

The two parts I referenced should never make it in, that wasn’t checked while you edited it!

They’re either bugs or you’re indenting arbitrarily (code style isn’t something to sprinkle on after writing, it’s something to maintain all the time)

Syntax issues are spotted while the code is parsed, long before the code starts running, they won’t “happen” while it’s running

    default:
    alert("What card is that?");
    }

Why is that brace aligned with the above line? Closing braces should be one indentation level to the left of the above line


#17

I was just going with what the page preset for indentation


#18

page?

Well, if you just start from the top and correct all the indentation you’ll probably be forced to put braces in all the right places in the process.


#19

page is being used lossely, it’s a codebit. I will go ahead and try to get proper indentation a little later