Still struggling with Challenge 1!

Incredibly frustrated! I’ve looked at the Hint links and read other people’s questions but I still can’t see what I’m doing wrong. I have:

const parseMessage = (origin, message) => {
return (“MC, Hello”);
};

I feel like I’m close because it says:
Expected: MC: Hello
Actual: MC, Hello

But when I remove the comma and add the colon, it still fails. I appreciate any hints that can be understood by a newbie! Thanks.

1 Like

Me too! I put
const parseMessage = (origin, message) => {
const expectedMessage = origin + ": " + message;
console.log(parseMessage);
return “MC” + ": " + “Hello”;
and it isn’t working. I hope someeone can help

1 Like

Same here, this is just one line of code but it’s causing me so many problems just because of formatting. You need to use a + sign between each entry and also have each entry in quotes. Colon wasn’t working for me either with just the MC (it works if I use more characters but not just with MC), so I used the + to add the colon in quotes as well separately, which works, but now it won’t accept the space. So I have only as far as MC:Hello but no space. Sigh. Will keep trying.

2 Likes

Is there a Lighthouse Labs moderator that checks these posts and offers help? I’m already feeling like I’m failing on day one! (And it’s actually day two, so I need to catch up, lol!)

1 Like

You need open bracket after return and then closed br after the last quotation mark (before the semicolon) - I just used that one line of code. But I couldn’t get the space after the colon to work, had to just enter the colon. Going to revisit it later tonight.

1 Like

In your code above, with return(“MC, Hello”);
The function parseMessage will return everything inside your double brackets " " . This means that, if you had return(“MC ! Hello”);

Your parseMessage function will return MC ! Hello.

Now when you remove the comma and add the colon, the parseMessage funcion will return MC: Hello. However, this is not what the task wants us to do.

It wants to take any parameter (origin, message) and when the parseMessage function is called, it will return a string using ‘origin’ and ‘message’

For example.

If the variable origin = I am
And the variable message = Canadian

With your example, when I call the function parseMessage(origin, message) you would still return MC: Hello.

When in fact it should return I am Canadian.

I hope that helps. I’m not a moderator, and I’m still new to programming. But I was able to complete both task 1 and 2.

3 Likes

Thank you so much @ddelrosario. I was thinking that I had to assign values to origin and message but when I tried that early on, I got error messages. I will go back and try again and will post afterwards!

2 Likes

@ddelrosario explains the issue and solution pretty much, but as a lesson, what you’re doing is called hardcoding which is forcing the program to adopt set values. And in the case of your code, you’re forcing a return value (which you want to do the least of in programming anything).

What const parseMessage = (origin, message) => { ... } is is a function that is expecting to receive 2 values you can use as variables (parameters) origin and message from wherever it is called from. Therefore, what your task for this challenge is is to use those 2 parameters to fit the format provided in the example.

For example (like the example they provide in the challenge), the following function call parseMessage("MC","Hello") would have origin = "MC" and message = "Hello". Therefore, to properly utilize the information (or parameters) provided, we create a string similar to origin+":"+message to try to match the expected answer.

Hope this helps in one way or another, and P.S. you don’t need brackets surrounding the value you’re returning.

1 Like

Hello I was wrong, looked closer at the fact that there were only two items in the string but I had added 4 items (MC, colon, space and Hello, when using return, made no sense because string only has 2 items. ) Finally figured out how to use console.log(origin); and console.log(message), which showed me at the bottom that they are both already defined as MC and Hello. So returning origin plus the colon and space plus message, with only the colonspace in quotations. Not returning MC and Hello. Which now makes sense but I sure was confused, did not realize that origin and message were already defined. Hope I haven’t confused you more!

1 Like

I thought I finally had it but this is still not passing:
const parseMessage = (origin, message) => {
origin = “MC”;
message = “Hello”;
console.log();
return origin+":"+message;
};

And thanks for your earlier comprehensive answer!

Still trying! Now I’ve tried to add two spaces after the colon:
const parseMessage = (origin, message) => {
origin = “MC”;
message = “Hello”;
return origin+": " +message;
};

It’s still not passing, even though I’m getting this:
Expected: MC: Hello
Actual: MC: Hello

Reread my first paragraph :sweat_smile:

You’re not supposed to give/set origin and message a value.

2 Likes

Hi, if you are still struggling here is some insight into what is happaning.

The challanges are us creating functions/methods, these methods pass in data like the orgin and message. These are variables that can be used in our method.

Havin the hard coded ‘MC: Hello’ is technically the right anwser, but what happens when lets say JPL send a message. They wouldn’t want to send a message with ‘MC: Hello’, they would want to say ‘JPL: Hope you made it okay’.

Therefore, we have to use those variables that tunnel in data into the method, in this case it is found between the () in the method decleration, origin and message.

All we have to do is combine them into one string and add a : between and return the result.

Hope this helps!

1 Like

Another note to remember:

Using a comma in a string outside of the quotations - i.e ("Hello", "how are you") - will put a space between the two described strings in quotations, or between variables if you are using a string variable. This would return Hello how are you

Using a plus sign outside of the quotations - i.e ("Hello" + "how are you") - will concatenate the values given, or in simpler terms, stick them together. So this would return Hellohow are you

Hope this makes sense.

1 Like

Your first line of code is already good enough to be a return function. Replace the "const expectedMessage = " section with return

1 Like

Hi thanks for the information about hard coding, someone else mentioned that as well yesterday - I was not familiar with that. I did finally solve this yesterday but the instructions were confusing because they stated to create a function but a function was already created. Unless they wanted us to create a new function which I did not do, I just called their function and added the colon+space. Also for a long time did not realize that the data was already there until I figured out how to properly use console.log() and also realized that the function is a constant. This seems to be just a challenge about how to add strings and add additional text but sure took me a long time! I am assuming that if we wanted JPL: Hope you made it okay we would need a new function but not sure at all, will save that for another day! Thanks for your comments they are helpful and very clear.

1 Like

Thanks for the tip! I tried this (below) but it doesn’t pass. I also tried adding a comma after the “:” but that causes 2 fails instead of 1. Thanks to you and the other commenters, I now understand that I don’t need to assign values AT ALL but I seem to be totally missing something else.

const parseMessage = (origin, message) => {
return expectedMessage = (origin+":" +message);
};

1 Like

const parseMessage = (origin, message) => {
return expectedMessage = (origin+":" +message);
};

try this
const parseMessage = (origin, message) => {
return (origin + ": " + message);
};

3 Likes

THANK YOU SO MUCH! I was so close and I thought I’d actually tried that but had not! You’ve saved me from being a potential Challenge 1 drop-out. :smiley: Now I think I understand the simplicity of what they are asking for instead of way overthinking. Hopefully that will stand me in good stead for Challenge 2.

3 Likes