# Comparison with greater than operator

Comparison with greater than operator
0

#1

check my code i have one wrong answer
this is my code

function testGreaterThan(val) {
if (val) { // Change this line
return “Over 100”;
}

if (val) { // Change this line
return “Over 10”;
}

return “10 or Under”;
}

// Change this value to test
testGreaterThan(10);

#2

The greater than operator (>) compares the values of two numbers. If the number to the left is greater than the number to the right, it returns true. Otherwise, it returns false.

#3

did you go to the link. i still don’t get where i went wrong

#4

you didn’t write any comparisons - if you want to compare something you need to have a left and a right

for instance if 3 < 2 returns false because 3 is not less than 2
if 4 > 3 returns true because 4 is greater than 3

The link you provided us with has no comparisons

#5

#6

if val < 10
under 25

how does that work for the numbers > 10 but < 25?

#7

thanks for try i don’t understand what you are saying i understand the less than but there is many numbers to work with i don’t how to do this

#8

#9

``````function testLessThan(val) {
if (val < 10) {  // Change this line
return "Under 25";
}

if (val <  54) {  // Change this line
return "Under 55";
}

return "55 or Over";
}
``````

You are saying "if the value of the variable val is less than 10, return text stating that the value is less than 25, which is true. However, the value 12 (for example) is also less than 25 but would not satisfy your condition (< 10) because it is greater than 10.

Similarly, “val < 54” does not work correctly if val is equal to 54; you would need to write either “val <= 54” or “val < 55” for the returned value to be correct.

Hopefully that makes sense.

#10

thanks for the video

#11

I tried it did not work. The question only wants me to use < not <=.

This my new code;

function testLessThan(val) {
if (val < 22) { // Change this line
return “Under 25”;
}

if (val <=54) { // Change this line
return “Under 55”;
}

return “55 or Over”;
}

// Change this value to test
testLessThan(54);
based on this code i got it wrong…

#12

why did you change it to 22 instead of some other number? There’s a big hint in the return statement right under if (val < 22)

#13

this is my new code

function testLessThan(val) {
if (val < 25) { // Change this line
return “Under 25”;
}

if (val <=54) { // Change this line
return “Under 55”;
}

return “55 or Over”;
}

// Change this value to test
testLessThan(54);
everything is correct but the last question is not(“You should use the < operator at least twice”);

#14

ok, forget about <= operator, this challenge does not allow it

use < operator instead, same as you did with a previous one

#15

function testGreaterOrEqual(val) {
if (val >= 20) { // Change this line
return “20 or Over”;
}

if (val >= 10) { // Change this line
return “10 or Over”;
}

return “9 or Under”;
}

// Change this value to test
testGreaterOrEqual(10);

#16

On the task return statements you have the answer (thats where the answer is so its a little confusing)
testGreaterThan(0) should return “10 or Under”
testGreaterThan(10) should return “10 or Under”
testGreaterThan(11) should return “Over 10”
testGreaterThan(99) should return “Over 10”
testGreaterThan(100) should return “Over 10”
testGreaterThan(101) should return “Over 100”
testGreaterThan(150) should return “Over 100”
So greater than 150 and 101 should return Over 100 so the first value should be equal val>100
Then greater than 100, 99 and 11 should return Over 10 so the second value should be equal val>10
Last 2 are the “else” thats left and that is 10 or Under

#17