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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help ... just started today

    Hi,
    trying this thing out and starting on code academy!
    can someone tell me what's wrong with this please???

    Thanks!

    confirm ("aRe yoU rEady to play?");
    var age=prompt("how oLd arE you?");
    if(age<18)
    {
    console.log("yoU cAn plaY But i tAke nO resPonsiBility!");
    }

    else

    {
    console.log("plAy on");
    }
    console.log("Snow White and Batman were hanging out at the bus stop, waiting to go to the shops. There was a sale on and both needed some new threads. You've never really liked Batman. You walk up to him.");
    console.log("Batman glares at you.");
    var userAnswer=prompt("Are you feeling lucky, punk?");
    if
    (userAnswer="yes");
    {
    console.log("Batman hits you very hard. It's Batman and you're you! Of course Batman wins!")

    }
    else
    [
    console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.")
    ]

  • #2
    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
    Use your error console (F12 key) to reveal errors.

    Hint:-

    else
    [
    console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.")
    ]

    See something wrong here?

    Also here

    if (userAnswer="yes");

    Be aware that prompts, confirm and alerts are all long obsolete and should be used (if at all) only for debugging. You should use DOM methods to obtain input data from and display messages to your users.


    Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can (and should) edit it to make it more meaningful.


    It is your responsibility to die() if necessary….. - PHP Manual
    Last edited by Philip M; 07-04-2013 at 07:55 AM.

    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.

  • #3
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry i will delete this post after i have the solution....
    still about unsure??
    thanks

  • #4
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im still unsure* please can someone help...

  • #5
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    [<=
    console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.")
    ] <=

    Is that what you wanted? (Rhetorical - no it isn't)
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #6
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    learna bit about console.log and where to view its output
    http://blogs.msdn.com/b/cdndevs/arch...debugging.aspx

  • #7
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    DanInMa, interesting article. It "only" applies to IE9/10? Not IE8 or FF?
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Actually, there's another *TWO* problems here:
    Code:
    if (userAnswer="yes");
    (a) The = operator in JS *ALWAYS* means "assignment", even in the condition of an if/while/etc.

    (b) The semicolon there says: This is the end of the statement.

    Who comes up with these very lame and useless homework assignments?
    Last edited by Old Pedant; 07-03-2013 at 09:43 PM.
    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.

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,456
    Thanks
    0
    Thanked 632 Times in 622 Posts
    Quote Originally Posted by Old Pedant View Post
    Who comes up with these very lame and useless homework assignments?
    Those people most in need of taking a JavaScript for beginners course - since they obviously think that they know JavaScript but even more obviously don't have any idea of how to write JavaScript properly.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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