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.

Make tests stricter for challenge "Decrement a number with javascript"

See original GitHub issue

You can pass the test by assigning 10 to the variable after decrementing it past that value.

It also doesn’t seem like the…

myVar = myVar - 1; should be changed.

…test is not working.

Incorrect code that is passing:

let myVar = 11;

// Only change code below this line
myVar = myVar - 1;
myVar--;
myVar = 10;

Forum: https://forum.freecodecamp.org/t/decrement-a-number-with-javascript-solution/490852

Challenge: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript

Tests: https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/decrement-a-number-with-javascript.md

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
lasjorgcommented, Jan 5, 2022

@ShaunSHamilton I don’t think your example is equivalent at all. The end value is supposed to be the result of decrementing, not just assigning a final value.

Yes, I believe that if a user uses the solution that @lasjorg stated, they know how -- works already, which fulfills the objective of the lesson.

Clearly, they do not if they can not decrement the starting value to the final value that is asked for. I see no reason why anyone that understands what the challenge is asking for would do that assignment.

We are not just blindly looking for the -- operator to be used. We are looking for the value 11 to be decremented to 10 using the operator.

An example would be a lesson where you ask someone to use a word in a sentence and they use the word incorrectly. They may have used the word but if it is used incorrectly they do not understand the word. Using it in a sentence means correctly using it, not just blindly shoving it into a sentence.


I would think a test with a regex that looks for an assignment to be good enough here.

Do not directly assign the value 10 to the myVar variable.

0reactions
import-braincommented, Jan 7, 2022
  1. The second test should be updated. Right now you can leave the initial code even though the test says it should be replaced. It should test that myVar = myVar - 1; is not present in the code.

    1. Check that no assignment is used.

I see, thank you for the clarification!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decrement a Number with JavaScript - Free Code Camp
In today's basic JavaScript tutorial, we utilize the decrement syntax. This is a fundamental lesson in JavaScript so it's important that you ...
Read more >
Decrement a Number with Javascript, freeCodeCamp Basic ...
In this challenge we find out how to decrement a variable by one. This can be done with the double minus sign "--"....
Read more >
Decrement (--) - JavaScript - MDN Web Docs - Mozilla
The decrement operator can only be applied on operands that are references (variables and object properties; i.e. valid assignment targets).
Read more >
Decrement a Number with JavaScript Help!
Now for the challenge you will have to decrement myVar . One way would be: myVar = myVar -1 , but they want...
Read more >
3 Amazing Types of Patterns in JavaScript - eduCBA
Design patterns are essential to solving this challenge – providing an ... Patterns in JavaScript (Number Patterns, Star Patterns, Character Patterns).
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