Tell us what’s happening:
I just looked at the video. This is too simple to be useful. What point are you making. Just saying >100 is >100; >10 is >10. Surely > 110 is also >100 but thats not allowed. The the 10 is there on its own with no if statement but is shows up in the video. I am missing something or you guys are just making this up to suite yourselves.
Your code so far
function testGreaterThan(val) {
if (val > 110) { // Change this line
return "Over 100";
}
if (val >11) { // Change this line
return "Over 10";
}
return "10 or Under";
}
testGreaterThan(10);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.
Challenge: Comparison with the Greater Than Operator
It’s supposed to be simple, it’s the very, very basics. You are being asked to check if val is greater than 100 in the first block, if val is greater than 10 in the second block. Not greater than 110, or 11
The point is that you understand what the > operator does (tests if the value on its left hand side is greater than the value on its right hand side)
So the function takes a number (val). If the number is greater than 100, the string “Over 100” is returned. Then if that isn’t the case, goes to the next if. If the number is greater than 10, the string “Over 10” is returned. Then if that isn’t the case, the number must be less than ten, so it goes to the final line and “10 or under” is returned.
If you put val > 110 in the first block and val > 11 in the second, as you have in your code, the function will return the wrong result:
if you run testGreaterThan(101), you will get the return value “Over 10”, because 101 is not greater than 110.
if you run testGreaterThan(11) you will get the return value “10 or under”, because 11 is not greater than 11.
Both of those answers are wrong, so the tests will fail: the return values should have been “Over 100” and “Over 10” respectively
the issue here is that if for example the input of the function is 101 (so if val has value of 101), it will not return "Over 100" because 101 > 110 is false
no you need to have a condition that will correctly return Over 100 when the value is over 100, so it needs to return true for val having values of 101, 102, 103, etc
if you write if (val > 120) {...} it will be true only for 121 and above
you are still missing the correct condition for values 101-120
Tell us what’s happening:
I have been going back and forth on this question to understand FCC exercise syntax. I have added comments to the exercise to show my current understanding. Am I on the right track.
Sorry to be taking up so much of your time but I need to be clear to move forward.
Your code so far
function testGreaterThan(val) {
if (val >100) { // Change this line
return "Over 100";//Inside the function block, returns if true.
}
if (val > 10) { // Change this line
return "Over 10";//second condition,new question.
}
return "10 or Under";//? Is this considered outside the function block??
}
testGreaterThan(2578);// I changed the 10 it still works, get a tick.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.
Challenge: Comparison with the Greater Than Operator
So what does the "10 or under " relate to. It just seem to be sitting out there orphaned. What’s it’s role, meaning, function. What should we be learning about it?
I might be in the wrong but
It’s the leftover value of the if else syntax
we already assigned the other 2 which are both the val above 11
so the leftover takes what is left everything bellow 11
and returns to tell u that
That’s why I thought it was outside the the block, Return outside the block is if its not valid. Isn’t that what the exercise was about not using return.
This in isolation makes sense to me but I was still trying to make sense of return.
I think I can see light at the end of the tunnel now.