The dumb thing needs a semicolon at the end - which is really stupid and here’s why…
Modern js does not require a semicolon at the end of lines of code (its part of the latest implementation - a feature - that you don’t have to do that).
Also, the semicolon is not required in freecodecamp challenges (other challenges besides this one) where the challenge is about variables - I know this because I have not been using the semicolon in all the previous challenges (the ones about variables prior to this one).
Why would they do this? Is it a bug? Does it need to be a feature request to make it like the others so you don’t have to have the semicolon?
The challenge is the same for everyone. But we can’t see your code from the link to the challenge, which is why it helps for you to post your code as well.
The Ask for Help button does this for you automatically.
It helps us help you when you provide the url in the address bar for the challenge (the link) and the code in the editor on the right side of the screen (both together are best). This won’t somehow leak private information. The url to the challenge is the same for everyone.
This is a second post on the topic because I did not understand how to use the ask for help button and what it would do. The original is here:
but it does not contain the challenge and code that I was asking about. That’s why I made this post in the proper way - because I was instructed how to ask for help properly (this post).
quote=“blahboybaz, post:1, topic:495952”]
I don’t understand how to pass this challenge and I don’t know what not passing a challenge means for the certificate in the end.
It acts like I’m using an " = " operator but I’m not. Afaict I am doing the increment right.
I actually know some js on my own (certainly how to increment a number and a lot more).
What am I doing wrong and / or how do I pass that challenge?
[/quote]
my code was…
myVar++ // Without the semicolon
But the following code solved the problem (passes the challenge)…
myVar++; // With the semicolon
Semicolons are not required by modern js and leaving them off works in other freecodecamp challenges (such as the ones prior the
Quote:
Increment a Number with JavaScript
let myVar = 87;
// Only change code below this line
myVar = myVar + 1;
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0
Yeah that just goes to the main issues page and I won’t guess about how to find it among all the others. It’s ok though. Thank you Jeremy. I passed the challenge and that’s enough for me.
If it should be allowed or not is debatable. I know some online curriculums enforce a style guide. I know CS50 maintained a style guide rule that had to be followed when submitting challenges (not sure if that is still the case).
It is not so much about if it works or not, but about consistency.
I don’t think fCC has really ever stood firmly on this issue. Just like with semicolons in CSS, you can leave off the last one in the style block but all or most of the regexs used by the tests (I think) will enforce an ending semicolon.
I personally wouldn’t mind fCC enforcing a style guide.
Thanks for pointing these things out. I hadn’t really thought about the details of it. It sound like (intuitively) that omitting semicolons in your code “AS” could result in errors or bugs (omitting semicolons sounds kinda “wild wild west” “shooting from the hip” way of writing code → unreliable). Is that correct?
You can leave them off if you know the rules and can debug any issues it might cause.
Some people just let their code formatter handle it (like Prettier) so when you save it adds the semicolons. The code in some cases might also get transpiled and end up looking much different. So the code you write and the code that runs are not actually the same (functionality the same, but doesn’t look the same).
Personally, I just like reading code with semicolons. It’s really more about the code as text than the code that gets executed.