CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Very simple problem with booleans, PLZ help! (http://www.codingforums.com/showthread.php?t=269556)

Doubleflame 08-04-2012 05:44 PM

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!

Philip M 08-04-2012 06:39 PM

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.

Logic Ali 08-04-2012 08:04 PM

Quote:

Originally Posted by Doubleflame (Post 1257694)
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 );


Doubleflame 08-04-2012 09:23 PM

Thanks!

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

Thanks guys!

AndrewGSW 08-04-2012 09:25 PM

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' );


Logic Ali 08-04-2012 09:51 PM

Quote:

Originally Posted by AndrewGSW (Post 1257733)
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


All times are GMT +1. The time now is 12:08 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.