Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator

Tell us what’s happening:
function testGreaterThan(val) {
if (val > 100) {
// Change this line
return “Over 100”;
}

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

return “10 or under”;
}

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

Your code so far


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

if (val > 10) {
  // Change this line
  return "Over 10";
}

return "10 or under";
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36.

Challenge: Comparison with the Greater Than Operator

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/comparison-with-the-greater-than-operator

Welcome, obburagasai.

Please note, for future posts:

  1. The “Tell us what’s happening” section is for you to ask a question, or tell use about the behaviour of your code.
  2. If you use the Get Help button in the lessons, it will prepopulate the Your code so far section with your code so far; there is no need to paste your code again.
  3. When posting code on the forum, please follow this guide: Forum Code Formatting

Now, could you please edit your post, to ask a question. We cannot help you, if we do not know the question to answer.

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

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

}

I couldn’t get why the code isn’t running , for the test cases
testGreaterThan(0) should return “10 or Under”

testGreaterThan(10) should return “10 or Under”
i tried with and without the if loop for the “10 or Under”

Your third if statement is what’s causing the problem.
You don’t technically need it, because the first if statement will check if val is greater than 100, if it is not, your code will move to the second if statement and check if val is greater than 10. If val is not greater than 10, we know it must be less than 10, and so a simple return "10 or under" will work here.

Additionally, the thrid if statement is checking for the wrong thing. All of your test cases are greater than 0, and so will all return "10 or under"

1 Like

The original code you have in the OP, works. You just change the return string for some reason (check capitalization).

1 Like

It worked thanks for the knowledge and telling the places which can be optimised.

1 Like