This Won't Work!


#1


Guys! I am adding onto my adventure and I can't figure out my mistake!
P.S. Where it says "You eat a poop" is where I will add on once this is fixed. I know it doesnt make sense, but I have to add something or else it will give me another error message. Everything looks good EXCEPT when I get to choosing the left or right path, it gives me this error message! I know this might be hard to solve since it is such a complicated game, but I really need help!


SyntaxError: missing ) after argument list


confirm("This is a text adventure. Please make sure to enter valid answers/choices for questions or else the game might restart.")
var ready = prompt("Now are you ready to start the adventure?").toUpperCase()
if (ready === "YES") {
    confirm("Let's start then!")
}
else if (ready === "NO") {
    confirm("Ok, I guess you can come again another time.")
}
else {
    confirm("Please enter YES or NO. I told you this in the beginning!")
    document.getElementById("client").reset()
}
var inventory = []
var gender = prompt("Are you a girl or a boy?").toUpperCase()
switch(gender) {
    case 'GIRL':
        confirm("Me too! Girl power! Girls rule, boys drool!")
    break;
    case 'BOY':
         confirm("Boys are awesome! Boys rule!")
    break;
    
    default:
     confirm("That is not even a gender!")
     document.getElementById("client").reset()
}
var name = prompt("What's your name?").toUpperCase()

switch(name) {
    case 'IZZY':
         confirm("Izzy! That's the most amazing name I have ever heard of!");
    break;
    
    case 'GRAMMY':
         confirm("Hi, Grammy!")
    break;
    
    case 'JOHNNY':
        confirm("Ayy, Johnny! Man, u so cool!")
    break;
    
    case 'BATMAN':
         confirm("Duh nuh nuh nuh nuh nuh nuh nuh nuh nuh nuh nuh nuh nuh nuh nuh BATMAN!!!!!")
    break;
    
    case 'KIP':
         confirm("Kip kip bo bip banana fanna fo fanna bo kip kip bo bip bo KIIIIIP!!!")
    break;
    
    case 'LUCAS':
         confirm("Yooooo Lucas y u playin my game?")
    break;
    
    if(name === '0' || '1') {
        console.log("No, it isn't")
    }
    else {
        console.log(name)
    }
    if(name === '0' && '1') {
        console.log("Pretty sure you don't have two names.")
    }
    else {
        console.log("Ok then.")
    }
    default:
    confirm (name + "! That name is awesome!")
}
var road = prompt("So, " + name + ", you are walking down a long road. You come across three paths. One is dark, scary, and covered with spikes. The next has flowers, candy, and mountains of gold. Finally, the last has nothing. It just keeps going down. Which path do you choose to walk down? Choose SCARY, CANDY, or NORMAL.").toUpperCase()

if (road === "CANDY") {
    var candyChoice = prompt("You start walking down the candy road. You pick up a piece of candy. Do you eat it? Answer YES or NO.").toUpperCase()
    if (candyChoice === "YES") {
        confirm("You ate the piece of candy and continue walking down. Turns out, the candy was poison and you immediately died.       THE END")
    document.getElementById("client").reset()
    
    }
    else {
        confirm("You continue walking down the path. You walk over to the mountain of gold. You go to pick up a piece, then suddenly, a giant dragon crawls out from the shadows and eats you!      THE END")
        document.getElementById("client").reset()
    }
}
else if (road === "NORMAL") {
    confirm("You walk for a while. You walk some more. You keep walking. You walk for days. You walk for a month. There is no end and you die of starvation.      THE END")
    document.getElementById("client").reset()
}
else if (road === "SCARY") {
    var scaryChoice = prompt("You start walking down the scary road. Suddenly, an animal walks near you. It looks very hostile and you have never seen an animal like this before! Do you ATTACK or STAY?").toUpperCase()
    if (scaryChoice === "ATTACK") {
        confirm("The animal turns around, looks at you, and lunges. It pounces on you and kills you with one bite.      THE END")
        document.getElementById("client").reset()
    }
    else if (scaryChoice === "STAY") {
        confirm("The animal walks toward you, sniffs you, and lays down. You pet it and it instantly loves you. It licks you all over and you are covered in slobber, but at least you aren't dead. The animal will now be your friend for the remainder of this story. ")
    }
    else {
        confirm("That is not a choice!")
        document.getElementById("client").reset()
    }
}
else {
    confirm("That is not a choice!")
    document.getElementById("client").reset()
}
var nameAnimal = prompt("You walk on the creepy path with the animal. You decide to give it a name. Would you like to name the animal? Answer YES or NO.").toUpperCase()

if (nameAnimal === "NO") {
    nameAnimal = "the animal"
}
else if (nameAnimal === "YES") {
    var animalName = prompt("What would you like the name the animal?").toUpperCase()
    if (animalName === name) {
        confirm("Don't name your animal your own name!")
        document.getElementById("client").reset()
    }
    else {
        confirm("You and " + animalName + " continue walking the path.")
    }
}
else {
    confirm("That is not a choice!")
    document.getElementById("client").reset()
}
var enemyAttack = prompt("You and " + animalName + " are walking down the path and something rustles in the bushes. Do you check it out or continue walking? Answer CHECK or WALK.").toUpperCase()

if (enemyAttack === "WALK") {
    var checkWalk = prompt("You and " + animalName + " walk down the path. You hear another rustling. Do you check it out or continue? Answer CHECK or WALK.").toUpperCase()
    if (checkWalk === "WALK") {
        var monsterAttack = prompt("The rustling got louder and out popped a huge ferocious monster! Do you ATTACK or RUN?").toUpperCase()
        if (monsterAttack = "ATTACK") {
            confirm("The monster rips you and " + animalName + " to shreds.      THE END")
            document.getElementById("client").reset()
        }
        else if (monsterAttack = "RUN") {
            confirm("The monster easily outruns you and rips you and " + animalName + " to shreds.     THE END")
            document.getElementById("client").reset()
        }
        else {
            confirm("That is not a choice!")
            document.getElementById("client").reset()
        }
    }
    else if(checkWalk === "CHECK") {
        confirm("You check the bushes and find a gold coin.")
        inventory.push("Gold Coin")
    }
    else {
        confirm("That is not a choice!")
        document.getElementById("client").reset()
    }
}
else if (enemyAttack === "CHECK") {
    confirm("You check the bushes and find a gold coin.")
    inventory.push("Gold Coin")
}
else {
    confirm("That is not an answer!")
    document.getElementById("client").reset()
}
var thingsToDo = prompt("What would you like to do now? If you want to check your inventory, enter INVENTORY. If you would like you continue the story, enter GO.").toUpperCase()
if (thingsToDo === "INVENTORY") {
    confirm(inventory)
    confirm("Ok, now let's continue.")
}
else if (thingsToDo === "GO") {
    confirm("Let's continue, then!")
}
else {
    confirm("That is not a choice!")
    document.getElementById("client").reset()
}
var leftOrRight = prompt("You see two paths. Would you like to go RIGHT, LEFT, or check your INVENTORY?").toUpperCase()
if (leftOrRight === "INVENTORY") {
    confirm(inventory)
}
if (leftOrRight === "RIGHT") {
    var comfortOrKill = prompt("You walk towards the right path. In the distance, you see a man crying. Do you COMFORT him, or KILL him and take his stuff?").toUpperCase()
    if (comfortOrKill === "COMFORT") {
        var catchTheRobber = prompt("You walk up to the crying man. You ask him what's wrong, and he says, 'Well, I just got robbed and the person who stole my things is over there. If you get me my stuff I will give you all of my money.' Do you choose to catch the robber and STEAL the things, or GIVE them back to the man?")
        if (catchTheRobber === "STEAL") {
            confirm("You run at the robber and tackle him. You take all of his things. When you start to walk away, the man yells, 'HEY! GET BACK HERE!' and he jumps on you. He steals all of your things, including the things from him. He beats you up and you wake up in a cell without " + animalName + ". You end up spending the rest of your short life (without food) not knowing how you got there.      THE END")
            document.getElementById("client").reset()
        }
        
        else if (catchTheRobber === "GIVE") {
            confirm("You run at the robber and tackle him. You take all of his things, and sprint back to the man. You give him his things back, and he gives you 5 Gold Coins. He thanks you and you are back on your way with " + animalName "." )
        
        }
        else {
            confirm("That's not a choice!")
            document.getElementById("client").reset()
        }
    }
    else if (comfortOrKill === "KILL") {
        confirm("You attack the man and kill him. He didn't have anything on him, so you had no benefit of killing him.")
    
    }  
    else {
        confirm("That isn't an answer!")
        document.getElementById("client").reset()
    }
    
}
else if(leftOrRight === "LEFT") {
    confirm("You eat a poop.")
}
else {
    confirm("That isn't an answer!")
    document.getElementById("client").reset()
}.


#2

I did not test your logic, but your code has a few minor syntax errors that you did not catch.

The below is missing an addition or concatenation operator (the plus sign) between animalName and "."

else if (catchTheRobber === "GIVE") {
            confirm("You run at the robber and tackle him. You take all of his things, and sprint back to the man. 
You give him his things back, and he gives you 5 Gold Coins. He thanks you and you are back on your way 
with " + animalName "." ) 
        
 }

You have an unexpected dot syntax at the end of your else clause (remove it).

else {
    confirm("That isn't an answer!")
    document.getElementById("client").reset()
}.

See if your code runs after that.


#3

Thank you so much! It worked.


#4

Also, do you like my game? It isn't done. I am going to make it much longer, but I want someone to review it.


#5

I'm currently more or less on the road, but I would love to play it. I should be able to provide some feedback in about an hour or so :slight_smile:

I might even learn something, as well!


#6

thanks! It means a lot.


#7

The adventure paths can get very elaborate. I enjoyed playing it. Making improvements and testing it will take quite a bit of time depending on how far you want to go, without making the adventure longer, even. Still, I spent a little bit of time playing, and here is my "First Impressions" feedback:

Improvements:
My initial suggestion as far as improvements is to try and play with functions, classes, and objects to see how that can improve your code. You may not even use classes, but I can see how objects and function may help your game if you plan on extending it. That way, you will get the most of what you learned in the JavaScript course.

Also, is there a particular reason you use confirm messages instead of alerts for things that don't require user input? Like the following?

This is a text adventure. Please make sure to enter valid answers/choices for questions or else the game might restart.

Problems I ran into

From a user aspect, I got a bit thrown off by the fact that if I put in an invalid answer, I'm not asked the same answer again. The prompt just vanishes.

If I answer "NO" to the first question, but then press okay on the following box, I still get asked if I'm a girl or a boy:

confirm("Ok, I guess you can come again another time.")

#8

Thank you so much for the advice. I did extend the game a lot today actually. The problem is, I don't know how to make it jump back in code. Let's say, someone answered a question wrong. I don't know how to make it ask the question again without writing the whole story over again in an if statement. I will write the new code, because I revised it a lot and extended it.


#9

I made a website for the game so that my friends could play it. Here is the link.
The Adventure


#10

By the way, on the website, if prompt vanishes, click the home button. I will try to change it to a Restart button.


#11

One way to do it is by creating a recursive function (a function that calls itself). Here's something to get you started, if you are interested:

function askQuestion(question){
       var answer = prompt(question).toUpperCase();
       if(answer =="YES" || answer =="NO"){
           alert("You typed yes or no.");
       }
       else{
             alert("That's not a valid answer! Try again!");
             askQuestion(question);
       }
}

askQuestion("Please type YES or NO");

#12

Do you know how I could make a GIANT one of those so that when you die, there is a checkpoint or something like that?
Because I would have to make the entire game again.


#13

Also, thank you because I am coding right now and your solution is awesome!


#14

I believe there can be checkpoints by separating parts of your game into functions or objects. I will get back to you on it with some ideas, and then you can make your own changes or come up with ideas from there. Probably sometime tomorrow or the day after.

As you improve your knowledge in a language, a good practice is to go back to applications and do a "Code Review", then improve the application. You will find your projects will evolve a lot, and you will have fun along the way.

And you're always welcome. I look forward to playing your game through all the changes you're making! :grinning:


#15

I thought I would share this with you in case you come up with more creative JavaScript projects on your own. During development of a project, if you want to share both the app and the code with your friends as you make improvements, but you don't necessarily want to open a new site for each one just yet, you can use something called JSFiddle.

It's a really popular tool for sharing and saving solutions on the fly. Here is an example of how it would work with your current project:
https://jsfiddle.net/missydecoded/q4rzfxhL/1/

Feel free to explore, and have fun coding!


#16

Thank you so much. Like I said, I made the new version. The one I put on here is definitely not very fun yet XD.


#17

Also, the ending for some reason, on my website won't work. I have the code right, and I don't know what the problem is. It should say something at the end instead of ending the game abruptly.


#18

Can you tell me which part is "the end"?
Is it anywhere you pick a path that leads you to die, or when you reach the longest possible path?

Without identifying the end, have you thought of just creating a separate function and calling it where appropriate?

Example:

if (candyChoice === "YES") {
            confirm("You ate the piece of candy and continue walking down. Turns out, the candy was poison and you immediately died.       THE END")
           theEnd()
    document.getElementById("client").reset()
    
        }

[...later or sooner in the code...]

function theEnd(){
   alert("Thank you for playing. Goodbye.");
}

#19

I know it's not helpful comment (i saw you already managed to do it) but i played your game. ITS SO FREAKING COOL but there's one thing i don't like!
YOU KILLED MY PET!:cry:


#20

Thanks. And your pet died because you probably did something wrong XD