Freecodecamp: An typo in a code description - 'if' statement, closed interval

Created on 11 Aug 2016  路  10Comments  路  Source: freeCodeCamp/freeCodeCamp

Challenge Comparisons with the Logical And Operator has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3; rv:11.0) like Gecko.
Please describe how to reproduce this issue, and include links to screenshots if possible.

In this _Challenge_, there is a part concerning an if statement:

issue

I think there is a mistake in a description of logic behind this code snippet as this _if_ statement will return "Yes" if _num_ is between 5 and 10 (5 and 10 excluded). According to your description, any number in a range (5, 6) and (9, 10) will return false, but it is not true.

My code:

function testLogicalAnd(val) {
  // Only change code below this line

  if (val >= 25 && val <= 50) {
    return "Yes";
  }

  // Only change code above this line
  return "No";
}

// Change this value to test
testLogicalAnd(25.001);

As you can see, this value is causing a function to return true, which is correct.

help wanted

Most helpful comment

@raisedadead Yes, I agree 100%. Are pull requests restricted only to those who create an issue, or just anybody, who's faster? I can submit a change today, if you don't mind.

All 10 comments

While the way it currently reads still makes logical sense to me (6 and 9 included meaning any number 6,7,8,9 will be accepted based on the statement), I could see how using the numbers 5 and 10 and the phrase "5 and 10 excluded" may be easier to follow since those are the numbers in the statement.

Alternatively, we could list out 6, 7, 8, 9 as values that would all return "Yes".

Well the instructions are correct, but I can agree that to a casual reader who can overlook the concept easily this is a bit misleading.

I think updating the instruction should clarify the same.

@dhcodes I like your suggestion:

Alternatively, we could list out 6, 7, 8, 9 as values that would all return "Yes".

Up for a pull request?

Or this could be first timers if you just lay out the exact changes to be done. :wink:

@dhcodes It doesn't really have to match the numbers used in statement, but it would be helpful, that's true. The little problem which I see here is that we are talking about natural numbers here only, and that's a bit misleading, especially after challenges concerning floats. :+1:

Based on a statement, 5.01 or 9.99 will do as well, but they aren't included in a range described as "will only return "Yes" if num between 6 and 9 (6 and 9 included)".

Hmmm... that is true and nullifies my recommendation of 6,7,8, and 9. Would it be redundant to change it to:
will only return \"Yes\" if <code>num</code> is greater than <code>5</code> and less than <code>10</code>

@gczarnocki I am afraid that's an incorrect analogy, in JavaScript you have only one type of number and it is floating point by default.

You can test this by pressing F12 on any browser window and going to the Dev Console, and doing a test like below:

image

Now coming to the point what might have got you confused is probably this:

if (val >= 25 && val <= 50) {
    return "Yes";
}

For 25.001 it is but of course true, literal translation 25.001 is greater than or equal to 25 and lesser than or equal to 50.

So, it's not about natural nos, integers, or any other type, at least in JavaScript.

Sorry hit submit pre-maturely. I think in that case we should just remove the

will only return "Yes" if num is between 6 and 9 (6 and 9 included).

and make it as

will only return "Yes" if num is greater than 5 and lesser than 10.

@raisedadead Yes, I agree 100%. Are pull requests restricted only to those who create an issue, or just anybody, who's faster? I can submit a change today, if you don't mind.

@gczarnocki I already started writing this for first-timers, but if that's you, go for it:

To fix this, in seed/challenges/01-front-end-development-certification/basic-javascript.json

change the line:
will only return \"Yes\" if <code>num</code> is between <code>6</code> and <code>9</code> (6 and 9 included).

to:
will only return \"Yes"\ if <code>num</code> is greater than <code>5</code> and less than <code>10</code>.

@gczarnocki please go ahead and make a change as you seem fit. Here are our Guidelines for Contributing.

Was this page helpful?
0 / 5 - 0 ratings