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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Very simple problem with booleans, PLZ help!

    Im trying to start learning javascript in code academy. So I found out that I can't complete one task with booleans.
    I will copy the task...

    Write code that will say true if I'm coding like a champ! has more than 10 characters.

    So my answer was:

    if ("I'm coding like a champ!"length)>10=true

    I have no idea in what order should I write these...

    Please help!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,989
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    The expression you want to evaluate must be contained in brackets.

    Code:
    var str = "I'm coding like a champ!"
    if (str.length >10) {  // returns true or false
    alert ("The length is over 10");
    }
    or

    Code:
    if ("I'm coding like a champ!".length >10) {
    alert ("The length is over 10");
    }

    Quizmaster: What three-letter word means "at this moment"?
    Contestant: Then.

    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.

  • Users who have thanked Philip M for this post:

    Doubleflame (08-05-2012)

  • #3
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by Doubleflame View Post
    Im trying to start learning javascript in code academy. So I found out that I can't complete one task with booleans.
    I will copy the task...

    Write code that will say true if I'm coding like a champ! has more than 10 characters.
    The result of a comparison is a boolean, so that is what you must show:

    alert( "I'm coding like a champ!".length > 10 )

    Or to save the result

    Code:
    var result = "I'm coding like a champ!".length > 10 ;
    
    alert( result );

  • #4
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Smile

    Thanks!

    It worked! I couldn't find information anywhere else. I tryed google and youtube, even went to deep web hack bb...

    Thanks guys!

  • #5
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    var result = "I'm coding like a champ!".length > 10 ;
    
    alert( result );
    That might display 1 rather than true:

    Code:
    var result = "I'm coding like a champ!".length > 10 ;
    
    if (result) alert( 'true' );
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #6
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by AndrewGSW View Post
    Code:
    var result = "I'm coding like a champ!".length > 10 ;
    
    alert( result );
    That might display 1 rather than true:
    If you convert a boolean to a number, you'll get 1 or 0. If the result of an expression is a boolean, then that is what it will display.

    alert( typeof ( "I'm coding like a champ!".length > 10 ) ) boolean

  • Users who have thanked Logic Ali for this post:

    Doubleflame (08-05-2012)


  •  

    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
    •