question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Challenge Name

https://www.freecodecamp.com/challenges/increment-a-number-with-javascript#?solution= var myVar %3D 87%3B %2F%2F Only change code below this line myVar%2B%2B%3B

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dmm10commented, May 11, 2016

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 notifications@github.com 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

1reaction
SaintPetercommented, May 11, 2016

@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}/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to understand the working of Pre-increment
The expression ++a is an lvalue while a++ is not and therefore it can't be the left operand of the assignment operator.
Read more >
Solving issues in using post and pre increment operators as ...
This only works if <variable> is something that can be incremented (i.e. an l-value). For instance, (4 + 8)++ would NOT compile, even...
Read more >
JavaScript arithmetic special operators - w3resource
The increment operator is used as follows: var1++ ( Post-increment ). ++var1 ( Pre-increment ). In the first case (i.e. post- ...
Read more >
Iterators in C++: An Ultimate Guide to Iterators - Simplilearn
++it // Using pre increment operator. Swappable: The values of the two input iterators that are pointing to different positions can be ...
Read more >
PHP Operators - Techotopia
The number and location of these operands in relation to the operators ... the result of the addition to the operand represented by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found