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);
did you go to the link. i still don’t get where i went wrong
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
if val < 10
under 25
how does that work for the numbers > 10 but < 25?
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
This is your code:
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.
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…
see the link
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)
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”);
ok, forget about <= operator, this challenge does not allow it
use < operator instead, same as you did with a previous one
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);
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
1 Like