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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Location
    Austin, Texas
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Need help with this code!!

    So when almost anyone wants to get better at something well they usaly search on the internet to get better!
    well I really wanted to get into Programming so i had foung Code Academy. Now what they have to offer isn't that bad,
    so i had i started on JavaScript.

    Some parts were confusing but now this a real problem it's were you have to make one of those text games.
    so here's the code i got so far and all the console says is but all it says is "SyntaxError: Unexpected string"

    confirm("Ready to kick some ***")
    var age = prompt("How old are you anyways");
    if(age <= 12) {
    console.log("ehh who gives a ****")
    } else {
    console.log("Get ready!!....")
    }
    console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'")
    console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
    var userAnswer = prompt("Do you want to race Bieber on stage?")
    if(userAnswer"yes") {
    console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!")
    } else {
    console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'")
    }

    PLZ HELP!!!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,211
    Thanks
    80
    Thanked 4,571 Times in 4,535 Posts
    You really don't see anything wrong with this?
    Code:
    if(userAnswer"yes")
    ???

    An if statement is usually based on a COMPARISON. Where is your comparison in that code?

    Compare that to your CORRECT earlier code:
    Code:
    if ( age <= 12)
    And incidentally, since this is a JavaScript question, it should have been asked in the JavaScript forum.
    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.

  • #3
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Your code:
    Code:
    if(userAnswer"yes")
    Corrected codde:
    Code:
    if(userAnswer="yes")

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,211
    Thanks
    80
    Thanked 4,571 Times in 4,535 Posts
    HeartDragon is WRONG!

    The corrected code is if( userAnswer == "yes" )

    HeartDragon's code would:
    (a) ASSIGN the string "yes" to the variable userAnswer. ALWAYS. EVERY TIME. Ignoring whatever value was already in that variable.
    (b) ALWAYS pass the "if" test as "true". Yes, really. Try it.

    But HeartDragon: This thread was over a month old. If the original poster can't be bothered to return to a post after more than a month, there's really no point in continuing the thread.
    Last edited by Old Pedant; 08-11-2014 at 04:43 AM.
    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.

  • #5
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    lol my bad, fatal typo there by me I often do that in code and have to fix it


  •  

    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
    •