Something wrong with challenge --> Increment a Number with JavaScript

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?

I fingered out the problem…

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?

It really helps to post your actual code and a link to the challenge instead of a picture.

I think this bug has a fix in progress?

You can check here:

GitHub Issues

It is possible to get a link to my challenge? To “MY” challenge or to “THE” challenge?

I’ll look

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.

I get what you’re saying but I want to be clear so I am not either posting personal information or a broken link that does not benefit anyone…

Are you suggesting I past the actual link to the actual challenge or that I paste the code in some paste site and share that line.

Either way I’m down with doing that just want to be sure I do it correctly

Thanks

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.

Ahh… I will do that. Thanks for explaining.

1 Like

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

Challenge: Increment a Number with JavaScript

Link to the challenge:

As I said above, I think this is a bug but I’m not sure if it’s being fixed yet. You can check at the link:

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. :slight_smile:

Just to be clear, I agree that this challenge should pass either way, semicolon or not.

That said, you should know there are some gotchas with leaving off semicolons. JS Tip of the Day: Missing Semicolon ASI Gotchas - web dev - kirupaForum

2 Likes

Pretty sure JavaScript has had ASI from the start. There is nothing modern about it, except for people using it intentionally as much as they do now.

Also, having it inserted automatically is not the same as not needing it.

12.9.1 Rules of Automatic Semicolon Insertion


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.

2 Likes

I can dig it

Either way I’m cool

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.

1 Like

Just to be clear, I agree that this challenge should pass either way, semicolon or not.

That said, you should know there are some gotchas with leaving off semicolons. [JS
Tip of the Day: Missing Semicolon ASI Gotchas - web dev - kirupaForum
(JS Tip of the Day: Missing Semicolon ASI Gotchas - web dev - kirupaForum)

Just saw this. Thanks for the link.