Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-04-2012, 05:44 PM   PM User | #1
Doubleflame
New to the CF scene

 
Join Date: Aug 2012
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Doubleflame is an unknown quantity at this point
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!
Doubleflame is offline   Reply With Quote
Old 08-04-2012, 06:39 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
Doubleflame (08-05-2012)
Old 08-04-2012, 08:04 PM   PM User | #3
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
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 );
Logic Ali is offline   Reply With Quote
Old 08-04-2012, 09:23 PM   PM User | #4
Doubleflame
New to the CF scene

 
Join Date: Aug 2012
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Doubleflame is an unknown quantity at this point
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!
Doubleflame is offline   Reply With Quote
Old 08-04-2012, 09:25 PM   PM User | #5
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Old 08-04-2012, 09:51 PM   PM User | #6
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
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
Logic Ali is offline   Reply With Quote
Users who have thanked Logic Ali for this post:
Doubleflame (08-05-2012)
Reply

Bookmarks

Tags
booleans, code academy, javascript, newbie

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:14 AM.


Advertisement
Log in to turn off these ads.