Comparison with the Greater Than Operator Tutorial

Comparison with the Greater Than Operator Tutorial
0

#1

Tell us what’s happening:
This is my code below, anyone to help out?

Your code so far


function testGreaterThan(val) {
  if (val > 99) {  // 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(99);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0.

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


#2

Problem: this comparison checks for a value which is over 99 when what’s needed is to return a value Over 100. (100 should not be included).


#3

Gosh!! This took me quite a long time to realise all I needed in my staement was just an else statement. This is the code al together for all that will have problem with it…

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

// Change this value to test
console.log(testGreaterThan(10));

#4

check my solution below, and like if it worked bro! Thanks anyways.


#5

You don’t need an else statement.

The code will go from top to bottom,
when it meets the requirements and pass the test
it returns the value and it stops there.

If it finds that the value is greater than 100,
it returns that value and stops there.

The problem with the code is the first comparison
(as suggested in my previous comment).

Try it without the else statement and you’ll see how
that beautiful green window appears on your screen.

Code:

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

#6

Thanks, bro. I noticed that too.


#7

You’re welcome!

Good Luck & Happy Coding.