freeCodeCamp: Does not accept logically equivalent answer

Describe the Issue

When I write the loop as:

  for (let i = 0; i < len; i++) {
    console.log(firstFive[i]);
  }

the response is evaluated to be correct. But similar approach and logically equivalent approach like:

  for (let i = 0; i <= len-1; i++) {
  // Only change code above this line
    console.log(firstFive[i]);
  }

is rejected.

In first loop, I converted<=to<to solve OBOE problem. In second loop, I changed the value i is being compared with like i <= len-1

both are acceptable approaches but the response is not accepted in case of 2nd approach.

Affected Page

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/debugging/catch-off-by-one-errors-when-using-indexing

Your code

function countToFive() {
  let firstFive = "12345";
  let len = firstFive.length;
  // Only change code below this line
  for (let i = 0; i <= len-1; i++) {
  // Only change code above this line
    console.log(firstFive[i]);
  }
}

countToFive();

Expected behavior

Code should be considered as valid and must be accepted.

Screenshots

No response

System

Device: HP 255 g7
OS: Manjaro Linux
Browser: Mozilla Firefox
Version: 101.0.1

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

Personally, I don’t think we need to add every single possible way to accomplish this task. The current regex handles the majority of learner solutions. This extra case should handle the overwhelming majority of learner solutions. We can add more if they become necessary.

File with the code.

I was going to suggest we reword the instructions, but I think it would be fine to account for both of these possible variations. Here’s a regex I made quick: i\s*<\s*len\s*;|i\s*<=\s*len\s*-\s*1\s*;

Screen Shot 2022-08-02 at 10 52 33 AM

@abhi3315 no, just English version should be changed. Other languages will be handled using the translation workflow.

In general, our rule of thumb is that valid code should pass the challenges.

Yeah, it looks like a reasonable fix to me.

Side note for @footedroom575 - i < len is much more common than i <= len - 1, so you should use the first in general over the second