I need some Javascript debugging

I’m trying to make a prompt game in my codebits and the problem is the first prompt isn’t working to ask what the player wants.

p.s. I have added some confirm statements and the problem is the if statements for those confirm
p.p.s how would I make it easier on me to loop back to the previous prompt?

We’re gonna need to see some code :wink:

sorry I have the link copied but I forgot to paste

https://www.codecademy.com/MinecraftMaster02/codebits/HyvPn8

here. Enjoy the link :blush:

just remember, if it works, to type in capital letters

  1. Please replace <script src='script.js'></script> from <head> section and put it before the closing tag </body>. Using JS code in the <head></head> is a bad practice, not recommended.
  2. I don’t think that using switch statements everywhere is a good idea, try to use if/else, if/else if/else instead.
  3. I think you need to do simple game with small functionality, for example GIANT SKELETON case, test it and if it works fine, expand your game by other cases. Try to describe all cases in order to understand for us how it should works. Step by step.
  4. Also I’ve made some corrections, please look at it.
var message = document.getElementById('message');
var clashRoyale = prompt("You are playing Clash Royale, and you have a full Elixir bar. what are you going to play? Do you play the GIANT SKELETON, ELITE BARBARIANS, FIRE SPIRITS, or WIZARD").toUpperCase();
//here's our little game of clash royale
switch (clashRoyale) {
    case 'GIANT SKELETON':
        var hit = prompt("The enemy played a skeleton army, what do you want to play? SKELETON ARMY, VALKIRE, or ARROWS" ).toUpperCase();
        switch (hit) {
            case 'SKELETON ARMY':
                var hit5 = confirm("Are you sure you want to play that card?");
                if (hit5 === true) {
                    alert("Your skeleton army destroyed the opposing skeleton army");
                } else {
					// i didn't catch this logic, just formatted
                    var hit = prompt("The enemy played a  skeleton army, what do you want to play? SKELETON ARMY, VALKIRE, or ARROWS").toUpperCase(); 
                    switch (hit) {
                        case 'SKELETON ARMY':
                            var hit5 = confirm("Are you sure you want to play that card?");
							break;
						
						// I replaced this case after 'SKELETON ARMY'
						case 'VALKIRE':
							var hit6 = confirm("Are you sure you want to play that card?");
							if(hit6 === true) {
								 alert("Your Giant Skeleton dies and so does your Valkire.");
							} else {
								var hit = prompt("The enemy played a  skeleton army, what do you want to play? SKELETON ARMY, VALKIRE, or ARROWS").toUpperCase(); 
								switch (hit) {
									case 'SKELETON ARMY':
										var hit5 = confirm("Are you sure you want to play that card?");
										if (hit5 === true) {
											alert("Your skeleton army destroyed the opposing skeleton army");
										} else {
											var hit = prompt("The enemy played a  skeleton army, what do you want to play? SKELETON ARMY, VALKIRE, or ARROWS").toUpperCase(); 
											switch (hit) {
												case 'SKELETON ARMY':
													var hit5 = confirm("Are you sure you want to play that card?");
											}
										}
								}
							} // you missed } here: close else statement
							break;
						
						case 'ARROWS':
							// what should be if user choice will be 'ARROWS'?
							break;
                    }
                }
                break;
		} // you missed } here: close switch (hit)
                
    case 'ELITE BARBARIANS':
        var hit2 = prompt("The enemy played a Minion horde. What do you want to play? WIZARD, SPEAR GOBLINS, or FIREBALL").toUpperCase();
        switch (hit2) {
            case 'WIZARD':
                alert("You nearly got to the Crown Tower, but did no damage");
                break;
            case 'SPEAR GOBLINS':
                ("You got four hits on the Crown Tower");
                break;
            case 'FIREBALL':
                alert("You got some alright damage on the crown tower");
                break;
                default:
                alert("That card isn't unlocked yet");
                break;
        }
        break;
        case 'FIRE SPIRITS':
            var hit3 = prompt("The enemy played Barbarians. what do you play next? SKELETONS, PEKKA, or WITCH").toUpperCase();
            switch (hit3) {
                case 'SKELETONS':   
                    alert("Good distraction");
					break;
                case'PEKKA':
                    alert("The Pekka took out the Barbarians, but died before it hit the crown tower");
					break;
                case'WITCH':
                    alert("The Witch, with the help of her skeletons, took out the Barbarians");
                break;
                default:
					alert("That card is to op for this game");
					break;
            }
        break;
        case 'WIZARD':
            var hit4 = prompt("The enemy played a Mini Pekka. what do you want to play? MINION HORDE, ARCHERS, or THREE MUSKETEERS").toUpperCase(); 
            switch (hit4) {
                case 'MINION HORDE':
                    alert("The wizard died but the horde was successful on damaging the crown tower");
                break;
                case 'ARCHERS':
                    alert("Neither troop survived");
                break;
                case'THREE MUSKETEERS':
                    alert("2 musketeers damage the crown tower");
                break;
                default:
                alert("That card isn't here right now, please leave a message after the tone. BEEP");
                break;
            }
            break;
	
	case 'ARROWS':
		// what should be if user choice will be 'FIRE SPIRITS'?
		break;
	
	case 'ARROWS':
		// what should be if user choice will be 'WIZARD'?
		break;
	
	default :
		alert("you don't have that card on your deck please choose one from the capital lettered choices");
}
1 Like

the switch works fine. I want the code to loop back to the top and start again before I get to "SWITCHING" the statements out

*pun intended

well… game has turned out fine, but the one thing people want me to do is make a way for “The Creator” to win… and I’m kinda stuck on that, if you will check my most recent forums posts