Freecodecamp: "++" operator not recognized in pre-increment position, (++myVar)

Created on 11 May 2016  Â·  6Comments  Â·  Source: freeCodeCamp/freeCodeCamp

Challenge Name

https://www.freecodecamp.com/challenges/increment-a-number-with-javascript#?solution=%0Avar%20myVar%20%3D%2087%3B%0A%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0AmyVar%2B%2B%3B%0A%0A

Issue Description

The test:
Use the ++ operator
fails when the pre-increment version of the "++" operator is used (i.e. "++myVar;") rather than the post-increment version. Nothing in the description of the task precludes the pre-increment version being correct.

Browser Information

  • Browser Name, Version: various
  • Operating System: various
  • Mobile, Desktop, or Tablet: multiple

Your Code

// If relevant, paste all of your challenge code in here
var myVar = 87;

// Only change code below this line
++myVar;


Screenshot

screen shot 2016-05-11 at 12 16 47 am

All 6 comments

@dmm10 thanks for the issue. Because we're targeting beginner coders, we wanted the challenges to be simple enough to teach a concept but not overwhelm learners with other details. Same goes for #8562.

cc/ @FreeCodeCamp/issue-moderators worth accepting this prefix operation?

I remember this was discussed earlier and more times in the chat, we could add separate challenges for pre/post increments/decrements.

But this is going to be confusing for beginners. Maybe we could relax the tests to allow pre but not change the test case message.

So advanced campers who are attempting these as in this case can pass the challenge and beginners are not overwhelmed as well.

@raisedadead I agree on just accepting the answer for flexibility but not change the test messages.

I think editing this line to the following will work. I'm not sure about escaping the parentheses but whoever takes this will have to check this.

assert(/([+]{2})?\\s*myVar\\s*([+]{2})?/.test(code) 

The code will break for ++myVar++ anyways so I think the above should be okay.

There is a similar case in #8562 so someone taking this can easily do the other 😄

@erictleung Won't the above code pass with just myVar? Since both ++ sections are optional, that will match just myVar.

Better to do:
/([+]{2}\s*myVar|myVar\s*[+]{2}/

@SaintPeter good point. I was being careless 😄 Thanks!

Thanks ya’ll! I couldn’t have asked for a better outcome.

Having poked your backend with alternate ‘correct' solutions to prior challenges and been impressed with your robust handling of them this situation stuck out a bit. And I was hoping to contribute to the polish of your beautiful project.

I appreciate the peak behind the curtain. It confirmed that the modification only required a simple regex edit and that ya’ll really are a copacetic group.

Kudos all around!

On May 11, 2016, at 12:39 PM, Eric Leung [email protected] wrote:

@SaintPeter good point. I was being careless 😄 Thanks!

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

Was this page helpful?
0 / 5 - 0 ratings