Freecodecamp: Challenge Concatenating Strings with the Plus Equals Operator More Info

Created on 28 Sep 2016  Â·  15Comments  Â·  Source: freeCodeCamp/freeCodeCamp

Challenge: Concatenating Strings with the Plus Equals Operator

https://www.freecodecamp.com/challenges/concatenating-strings-with-the-plus-equals-operator

Issue Description

In the instructions given, I provided the following code:

var myStr;
myStr += "This is the first sentence. ";
myStr += "This is the second sentence.";

Resulting in...

myStr = "undefinedThis is the first sentence. This is the second sentence."

Which is as expected but I think new coders may not understand (or have forgotten) why myStr begins with "undefined". I suggest a hint to remind campers that myStr should first be initialized to the first sentence and then they can use the += operator.

Browser Information

Win10 Desktop Chrome, Version 53.0.2785.116 m (64-bit)

discussing

Most helpful comment

@texas2010 You had time to comment to not help? smh. @meamay07 If you would look at the above examples, these guys initialized the variable(var) first, so there should be 3 sentences here:

var myStr=" ";
myStr+="This is the first sentence.";
myStr+=" This is the second sentence.";

Good Luck!

All 15 comments

I just noticed that the example ourStr already shows this procedure, so maybe the challenge is fine as is (I tend to overlook the examples which I assume is NOT what a new coder would do).

I've also seen from other challenges that string literals are generally initialized to "" instead of being just declared and not initialized, so I suppose it boils down to whether FCC wants campers to deal with an uninitialized string literal in the first place.

@afable thanks for the feedback. I want to say the challenges are built so that there is some guidance but not too much. There should be bits of critical thinking involved in solving the challenges.

In this case with the code you have where you initialize the variable first, the resulting string produces an unexpected undefined at the beginning of the string. This may (and probably should) raise some flags in the coder's head.

So I don't think there is too much alarm for this challenge. The key and I think flow of the challenges is to see the example and modify it slightly to complete the challenge. But I'm open for discussion on the topic if others feel additional comments are needed about the challenge.

Closing since challenge seems fine as is.

Right but on the first example you used at the top of the page it says undefined, but if you take the first + sign out it comes back as correct. as such:

var myStr;
myStr = "This is the first sentence. ";
myStr += "This is the second sentence.";

When i run it like this, it green lights it and doesnt spit back the "undefined" part.
Thanks

@Drizzt91AJ But if you did:

var myStr = "";
myStr += "This is the first sentence. ";
myStr += "This is the second sentence.";

It would also work.

var myStr="This is the first sentence.";
myStr += "This is the second sentence.";

what did I do wrong?

@meamay07
Please use the HelpJavaScript chat room for getting challenge related help.

Happy Coding.

@texas2010 You had time to comment to not help? smh. @meamay07 If you would look at the above examples, these guys initialized the variable(var) first, so there should be 3 sentences here:

var myStr=" ";
myStr+="This is the first sentence.";
myStr+=" This is the second sentence.";

Good Luck!

@JSWesterfield, GitHub Issues are for reporting bugs on the website only.

My apologies this might be a incorrect button press.

On Sat, Dec 24, 2016 at 6:16 AM, Lance notifications@github.com wrote:

@JSWesterfield https://github.com/JSWesterfield, GitHub Issues are for
reporting bugs on the website only.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/10944#issuecomment-269085961,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATKsa_D14Rpo35FGLiAJx4Q-wduXbX9_ks5rLSlCgaJpZM4KISWN
.

@JSWesterfield, it is fine. people have to go to Chat room or forum for ask help. but not this issue thread. that is why I gave a link to that person.

@erictleung
General feedback: As a beginner this lesson threw me off. I been writing everything down and "undefined" slipped by real good lol. Gotta watch out for information flooding. Holding someones hand is damaging but quick reminders about random past lessons would go a long way in a forward moving environment, background nagging keeps old info as fresh as new. Other than this one, all is well so far. But most likely my own fault lol.

Edit: perhaps a tiny box at the bottom of all the important stuff, and it just randomly reminds the student with past one liner information. I tend to use help chat for this purpose, if I didn't help peoples issues I'd forgot some what was learned if not used a lot.

i'm stuck on this one too
here's my code
var myStr = "This is the first sentence."; myStr += "This is the second sentence";
heres what im missing

myStr should have a value of This is the first sentence. This is the second sentence.

@codenamecobra
Please use the HelpJavaScript chat room for getting challenge related help.

Happy Coding.

var myStr = "";
myStr += "This is the first sentence. This is the second sentence.";

It would also work.

Was this page helpful?
0 / 5 - 0 ratings