-1

Can anyone tell me where I am wrong with this code? Its supposed to be a simple Question/Answer prompt with various routes based on answers. Just a forewarning I am a coding noob so Thank you ahead of time for helping me out!

var answer = prompt("Would you like to visit the Longneck or T-rex exhibit first?");
  
var enter = prompt("Welcome to Jurassic Park, are you ready for an adventure?");
  if (enter == "yes"){
    console.log("Ok, lets go!");
  }
  else{
    console.log("Well too bad, we're already here.");
  }
  var exhibit = prompt("Would you like to visit the T-rex or the Raptor exhibit first?");
    if( exhibit == "T-rex"){
      console.log("Good choice, its actually feeding time... So exciting!");
    }
      var trex = prompt("Wow look at the T-Rex, it's right next to the fenc... OMG it just broke out!! Should we get out of the car and hide or stay in the car and try and drive away. Answer run or drive.");
        if(trex == "drive"){
          console.log("Good choice! Lets break off the track and drive toward the basecamp!");
        }

          var survived = prompt("You made it back to basecamp but the t-rex is on your ass! Do you run inside or run and hide in the jungle? Answer inside or jungle.");
            if(survived == "inside"){
              console.log("Nice you got in and locked the door, after a while the t-rex leaves and your helicopter rescue comes to the rescue. You survived this nightmare.");
            }
            else(survived == "jungle"){
              console.log("The t-rex chases you down and you get eaten. You died a horribly gruesome death.")
            }

        else(trex == "run"){
          console.log("The T-rex chases your group down and you die a horrible death")
        }

    else(exhibit == "Raptor"){
      console.log("Nice! The raptors are some of our smartest dinosaurs");
      }
        var raptor = prompt("You made it to the raptor cage but as soon as you drive up you see the fence has been slashed open. Do you stay on the track that your automatically driving on or do you bust off the track and drive away as fast as you can? Answer stay or drive.")
          if(raptor == "drive"){
            console.log("You drive as fast you can but you are noticed by the raptors. They start to chase after you!")
          }

            var run = prompt("You get back to the basecamp but the raptors chased you all the way. Do you run inside and lock yourself in or run to the jungle and try to hide? Answer inside or jungle.")
              if(run == "inside"){
                console.log("You succesfully run inside and lock the door before the raptors can get you. They try for hours to get in but then run off. Your rescue helicopter comes and you survive.")
              }
              else(run == "jungle"){
                console.log("The raptor smell you out and rip you and your friends into a million pieces and eat all of ya'll. You died a terrible death.")
              }
              
          else(raptor == "stay"){
            console.log("You drive slowly passed the fence and immediately get noticed by the raptors. They claw their way in your car and eat you and all of you group.")
          })
WalkMike
  • 7
  • 2
  • 5
    I think http://codereview.stackexchange.com/ will be a better fit for this question – Arun P Johny May 01 '15 at 03:03
  • @ArunPJohny - code review is for code that is working, but the OP wants to solicit improvements. It sounds like this code is not working. – jfriend00 May 01 '15 at 03:04
  • 5
    What does not work as you expect?. You will probably need to describe exactly what the code is supposed to do that it is not doing now for us to have any idea how to help. – jfriend00 May 01 '15 at 03:05
  • 2
    I'm voting to close this question as off-topic because it belongs on codereview.stackexchange.com. – Justin Niessner May 01 '15 at 03:07
  • 1
    If there's something that's not working as you expect, you need to clarify what that is. If you're just looking for a critique of your code, you'll want to try [codereview](http://codereview.stackexchange.com). – Krease May 01 '15 at 03:11
  • `"Can anyone tell me where I am wrong with this code?"` is not a specific enough question. We don't know what doesn't work or what it is supposed to do that it is not doing? Your question will be closed shortly unless you clarify. Also, I should advise you that StackOverflow is not an online forum where you post and check back the next day. When you post a question here, you should check back frequently within the first 30 minutes to see if everyone understood your question or if you need to clarify. Otherwise, your question will get closed if it is not clear. – jfriend00 May 01 '15 at 03:33
  • Try pasting your code into http://jshint.com/ and see all the wrong things that it reports. – jfriend00 May 01 '15 at 03:36
  • 1
    To the other commenters, this code is clearly broken. http://codereview.stackexchange.com is ONLY for working code that is soliciting improvements so it is NOT appropriate for this code. The question should be closed because it does not do follow this guidelines: Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. – jfriend00 May 01 '15 at 03:37

3 Answers3

1
else(exhibit == "Raptor")

else(run == "jungle")

and

else(raptor == "stay")

and two other lines like this are not valid statements. It should be else if().

The console output says

SyntaxError: missing ; before statement

For your case it’s meaningless but you have to ensure that your syntax is correct first to avoid this error message. To validate JS code you can use JSHint.

Apparently, the last ) should be removed as well.

Then you only need to review your logic — i. e. your if, else if and else blocks in order to confirm whether the program flow (decisions and prompts, etc.) is as you expect it to be (because, as jsve said, some of your if blocks close too soon).

Community
  • 1
  • 1
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
1

You are closing your if statements too soon.

var answer = prompt("Would you like to visit the Longneck or T-rex exhibit first?");

var enter = prompt("Welcome to Jurassic Park, are you ready for an adventure?");

if (enter === "yes") {
    console.log("Ok, lets go!");
}
else {
    console.log("Well too bad, we're already here.");
}

var exhibit = prompt("Would you like to visit the T-rex or the Raptor exhibit first?");

if (exhibit === "T-rex") {
    console.log("Good choice, its actually feeding time... So exciting!");
    // <-- NO Close brace here, that way, the code below (until the brace will
    //     only be executed when exhibit === "T-rex"

    var trex = prompt("Wow look at the T-Rex, it's right next to the fenc... OMG it just broke out!! Should we get out of the car and hide or stay in the car and try and drive away. Answer run or drive.");
    if (trex === "drive"){
        console.log("Good choice! Lets break off the track and drive toward the basecamp!");
        // <-- No close brace here either

        var survived = prompt("You made it back to basecamp but the t-rex is on your butt! Do you run inside or run and hide in the jungle? Answer inside or jungle.");
        if (survived === "inside") {
            console.log("Nice you got in and locked the door, after a while the t-rex leaves and your helicopter rescue comes to the rescue. You survived this nightmare.");
        } else(survived == "jungle") {
            console.log("The t-rex chases you down and you get eaten. You died a horribly gruesome death.")
        }
    } // <-- insert close brace here. This ends the if (trex === "drive")
      //     scenario
    else(trex == "run") {
      console.log("The T-rex chases your group down and you die a horrible death")
    }
// <-- insert close brace here. This ends the if (exhibit === "T-rex")
//     scenario
else if (exhibit === "Raptor") { // <-- need to use "else if" here
    console.log("Nice! The raptors are some of our smartest dinosaurs");
    // <-- no close brace here
    var raptor = prompt("You made it to the raptor cage but as soon as you drive up you see the fence has been slashed open. Do you stay on the track that your automatically driving on or do you bust off the track and drive away as fast as you can? Answer stay or drive.")
    if (raptor === "drive") {
        console.log("You drive as fast you can but you are noticed by the raptors. They start to chase after you!")
    }
    var run = prompt("You get back to the basecamp but the raptors chased you all the way. Do you run inside and lock yourself in or run to the jungle and try to hide? Answer inside or jungle.")
    if (run === "inside") {
        console.log("You successfully run inside and lock the door before the raptors can get you. They try for hours to get in but then run off. Your rescue helicopter comes and you survive.")
    }
    else if (run === "jungle") { // <-- need to use "else if" here
        console.log("The raptor smell you out and rip you and your friends into a million pieces and eat all of ya'll. You died a terrible death.")
    } 
    else if (raptor === "stay") { // <-- need to use "else if" here too
        console.log("You drive slowly passed the fence and immediately get noticed by the raptors. They claw their way in your car and eat you and all of you group.")
    } // <-- no ")" here, there's no "(" to match it.
} // <-- need a closing else if (exhibit === "Raptor") scenario

Other notes:

Community
  • 1
  • 1
Sumner Evans
  • 8,951
  • 5
  • 30
  • 47
0

Your closing your if and else statements too soon and you missed 'if' in 'else if'...

var answer = prompt("Would you like to visit the Longneck or T-rex exhibit first?");

var enter = prompt("Welcome to Jurassic Park, are you ready for an adventure?");
  if (enter == "yes"){
    console.log("Ok, lets go!");
  }
  else {
    console.log("Well too bad, we're already here.");
  }
  var exhibit = prompt("Would you like to visit the T-rex or the Raptor exhibit first?");
    if( exhibit == "T-rex"){
      console.log("Good choice, its actually feeding time... So exciting!");
      var trex = prompt("Wow look at the T-Rex, it's right next to the fenc... OMG it just broke out!! Should we get out of the car and hide or stay in the car and try and drive away. Answer run or drive.");
        if(trex == "drive"){
          console.log("Good choice! Lets break off the track and drive toward the basecamp!");

          var survived = prompt("You made it back to basecamp but the t-rex is on your ass! Do you run inside or run and hide in the jungle? Answer inside or jungle.");
            if(survived == "inside"){
              console.log("Nice you got in and locked the door, after a while the t-rex leaves and your helicopter rescue comes to the rescue. You survived this nightmare.");
            }
            else if(survived == "jungle"){
              console.log("The t-rex chases you down and you get eaten. You died a horribly gruesome death.")
            }

        }
        else if(trex == "run"){
          console.log("The T-rex chases your group down and you die a horrible death")
        }
    }
    else if(exhibit == "Raptor"){
      console.log("Nice! The raptors are some of our smartest dinosaurs");
        var raptor = prompt("You made it to the raptor cage but as soon as you drive up you see the fence has been slashed open. Do you stay on the track that your automatically driving on or do you bust off the track and drive away as fast as you can? Answer stay or drive.")
          if(raptor == "drive"){
            console.log("You drive as fast you can but you are noticed by the raptors. They start to chase after you!")

            var run = prompt("You get back to the basecamp but the raptors chased you all the way. Do you run inside and lock yourself in or run to the jungle and try to hide? Answer inside or jungle.")
              if(run == "inside"){
                console.log("You succesfully run inside and lock the door before the raptors can get you. They try for hours to get in but then run off. Your rescue helicopter comes and you survive.")
              }
              else if(run == "jungle"){
                console.log("The raptor smell you out and rip you and your friends into a million pieces and eat all of ya'll. You died a terrible death.")
              }

          }
          else if(raptor == "stay"){
            console.log("You drive slowly passed the fence and immediately get noticed by the raptors. They claw their way in your car and eat you and all of you group.")
          })
    }
Shawn Jacobson
  • 1,352
  • 8
  • 13