Concatanating Strings with the Plus Equal Operator

I actually got the exact same code to work on VSCode but it won’t recognize the code that I entered. I reset the code and reenter it but I keep getting the same errors when I know I entered the code the way it should be. Could someone please help?


// Only change code below this line

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Concatenating Strings with the Plus Equals Operator

Link to the challenge:

Is the final result supposed to have a space in the front?

A space in the front…? I am sorry but I am not following you. A space in the front of what? After the sentence and before the last double quotation? - I tried removing that and I messed with the += operators thinking that that may be the reason why my code is not being acknowledged as appropriate. I do not think it is due to the spaces. The challenge clearly states that I need a space in between the two strings BUT in the steps that it has on the bottom left side, there is no error indicating that I am missing a space in between where in the previous example, that example actually did demonstrate that I was missing a space and a \t and what not ( in the bottom-left hand side).

The space at the front of the first sentence… The part I quoted…

Hi @JosephGarza !

Welcome to the forum!

I would suggest adding these two console.log statements at the end of your code so you can see where the error is.

// Only change code below this line

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

//correct output
console.log('This is the first sentence. This is the second sentence.')

//your output
console.log(myStr)

You should see this output in the console.

The top sentence is the correct output while the bottom sentence is your output.

You need to fix that extra space at the beginning in order to pass the tests.

2 Likes

Ok, so I deleted the previous message cause I took a peek at the screenshot that I shared with you (the one where you can clearly see that I added a space between the first letter of the first word and the first double quotation). Now, I’ve noticed that space you are telling me about, so I went back to remove those spaces - which I am certain you will agree with me from the screenshot I shared with you just now, HOWEVER, that issue still remains. JUST YOU WATCH AND SEE!

I took it upon myself to show the previous answer along side the new one (on the left). Please tell me you see something that I do not. I am working along side VSCode cause I would like to get a tad bit more practice with certain of the tasks and I just can’t seem to understand why it won’t work on Free Code Camp dot org.

Well, you did remove the space here in your new code

Removing that space is correct.

However, you also removed the space here which I didn’t want you to remove.

Now your code looks like this.

// Only change code below this line

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

//correct output
console.log('This is the first sentence. This is the second sentence.')

//your output
console.log(myStr)

If you look very carefully at the output in the console, they are not same.

The top sentence is the correct input.
While the bottom sentence is your input.

I know these are small details but it is important. :grinning:

You need to make sure that your input matches the input you see in the console.

The spacing has to be exact.

You are one space away from passing this challenge.

Hope that helps!

Both of the screenshots you shared are incorrect.

Use the console.logs to compare your input with the correct input.

You are close to passing the challenge.
You just need to be more precise with the spacing details.

Hope that helps!

1 Like

Please share code instead of pictures. It is hard to read code from pictures.

You need exactly one space between the sentences and zero in front of the first one.

1 Like

Thank you for the input. I will make it a priority to submit code. I thought about what you said and I can see how that benefits in many ways. I’ll share code from here on out.

Hello! Trust you’re keeping safe. Sorry, so long and thanks for your feedback. I will get to the tutorial in. a few hours and it looks like I got some reviewing to do and I think this is a lesson on following instructions verbatim. Again, thank you for your feedback. I appreciate it wholeheartedly. I’ll keep you posted. :fist_left:

Well! I got it. Thank you so much, J ! I mean, I actually did move forward with the tutorial, I just skipped it, but I did feel like there was something that I just wasn’t quite grasping - that darn space, and that’s that with that… lol. Thanks again!