How to compare the strings length?


#1

Let's compare two numbers to return a true result:

First, write the string "I'm coding like a champ".
Next, find the length of the string (like you did here).
Then, compare the string's length to see if it is greater than 10.

How am i suppose to compare the string's length?


#2

Hey Almoharith,

To compare something, you can use a bunch of comparison operators:

a > b (if a is larger than b)
a < b (if a is less than b
a >= b (if a is larger than or equal to b)
a <= b (if a is less than or equal to b)
a == b (if a equals b)

In this case, you'd want the first one, if the string's length (do you know how to get that?) is greater than (>) 10 :)


#3

I was stuck on this too because the example looks incomplete, however a friend showed me there is a SLIDER-BAR under the example. If you grab it and slide it you can SEE THE REST of the example, making it MUCH less frustrating!


#4

@zystvan is correct.

By the way, in case you didn't know how to get the length of a string, it's like this:

"I'm coding like a champ".length

and to complete your comparison:

"I'm coding like a champ".length > 10

#5

@jibblyj It's length, not length() :)
I'm not sure why.


#6

I'm pretty sure it used to be :wink:


#7

Maybe it's a jQuery function, rather than a plain JS one or something - idk :)


#8

I just cut and paste it exactly according to my specifics and it isn't working.

Something is missing from this lesson.


#9

@awakenedmuse Try refreshing the page or switching browsers. We can't really help you without seeing your code, even if you did copy/paste it.