Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with a text based game i am making

    so i am working on making a text based game and i ran this quick little sippet and it ran but not like a text based game would. does anyone know what i am doing wrong




    prompt ("are you ready to play")
    if ("yes")
    {prompt ("you wake up in a forrest")}
    if ("go south")
    {prompt ("you run into a troll as you go deeper in to the forrest, what do you do")}
    if ("no")
    {console.log ("whatever then")}

  • #2
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so it asks all the things but that is also the problem, if i say no at the first "if" it will still ask me everyhing else

  • #3
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so i just changed what my code says to
    [var rtp = prompt ("are you ready to play");

    if ("rtp = yes"){
    prompt ("you wake up in a forrest");
    }
    if ("go south"){
    prompt ("you run into a troll as you go deeper in to the forrest, what do you do");
    }
    if ("rtp = no")
    {console.log ("whatever then")}]

  • #4
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Hi duke,

    the prompt() function returns a value, hopefully text the user entered. So, you need to catch it each time you use prompt, like you do here:

    var rtp = prompt ("are you ready to play");

    this:
    if ("rtp = yes")

    should be:
    if (rtp == "yes")


    1 equal sign is an assignment ( var x = 5)
    2 equal signs is a comparison ( if (x == 5) )

    You really should ask these questions at codeCademy
    Where the world once stood
    the blades of grass
    cut me still

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    prompts are obsolete and are no longer used in any serious application.

    You need to capture any possible user response:-

    Code:
    var rtp = prompt ("Are you ready to play?", "");
    rtp = rtp.toLowerCase().substring(0,1);  // first letter of response in lower case
    if (rtp == "y") {
    // proceed

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    And how is the user to know he/she must type "go south" instead of just "south" or instead of "down" or or or ....

    Is it really worth the time to create yet another obsolete text-based game?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Quote Originally Posted by Old Pedant View Post
    And how is the user to know he/she must type "go south" instead of just "south" or instead of "down" or or or ....

    Is it really worth the time to create yet another obsolete text-based game?
    Hi Pedant,
    This is either one of the Codecademy exercises or an attempt by Duke to expand upon the original exercise. The 'students' there are not given much in the way of 'real life' instruction. They are simply told to do this, do that and then validated on their code (prompts, unnecessary braces, etal are par for the course). So, they aren't told they should have a 'help' command, nor how to put anything anywhere other than the console.

    Btw: I dropped out of the 'academy' after one of the moderators told me the staff has no intention of supporting IE because of some article written by a chrome holy-roller in computerworld
    Where the world once stood
    the blades of grass
    cut me still

  • #8
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    And how is the user to know he/she must type "go south" instead of just "south" or instead of "down" or or or ....

    Is it really worth the time to create yet another obsolete text-based game?
    i chose do have the answers say what they do because that is standard text based game language for you to use, if on didnt use that i would be confused. and i am making another obsolete text based game because at my school every 2 months we have to have two projects that we have worked on, so i needed something that i could do with coding that i would realistically be able to achieve in that amount of time


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •