Challenge 12 Megathread

Welcome to challenge #12!

Use this thread for any and all questions relating to challenge 12

The starting code should be :

// Add your parseMessage function here if you want!

const parseTranscripts = (messages) => {

  // Code here!

}

If it’s not like that, please copy and paste this version!

2 Likes
const ownMessages = [
  {origin:"Darth Vader", message:"I'm your FATHER!"},
  {origin:"Luke Skywalker", message:"Nooooo!"},
];
16 Likes

One extremely key piece of information was left out from the Hint section. Scope. I’d come up with a couple solutions that, while they worked in my local IDE, failed to pass the tests until I factored in Scope.

Suggested Reading: Scope - MDN Web Docs Glossary: Definitions of Web-related terms | MDN

3 Likes

The function does not have any parameters. Are there any arguments passed on to the function?

const parseTranscripts = ( ) => { }

SheLovesMeNot

3 Likes

Hello!

Seems there was a small bug in the deployment, it should have messages like so :


// Add your parseMessage function here if you want!

const parseTranscripts = (messages) => {

  // Code here!

}
1 Like


I can’t understand why I have the right array values but it won’t accept the answer. Please help

There’s somewhere where “origin” belong to an object that’s undefined.

There are multiple ways to do a loop as well, I recommend exploring those :slight_smile:

I had noticed that too and passed a “message” parameter…

dont hard code the values for message .

This is confusing me. I can pass the first two tests but I fail the third.

I create a new array, that works.
I run this loop, it works.

for (let i = 0; i < messages.length; i++){
parsedMessage.push((messages[i].origin + ": " + messages[i].message).text);
}

I return my parsedMessage and it is an array and passes the first two tests.
Why does it fail the third? The wording of question 2 and 3 are are identical.

it’s here, where in parsedMsg…[i]

Hey TCYoung,

I ran your code through with the console.log(parsedMessage) and it returned an array with null components instead of the proper origin and message strings.

The error lies in something you have added to the following line:
parsedMessage.push((messages[i].origin + ": " + messages[i].message).text);

Once fixed it should pass all 3 tests, hope that helps point you in the right direction!

A couple of things:

  1. Don’t hard code in the “messages” object because it’s already provided
  2. Don’t define the same function twice (parseMessage)
  3. Create two arrays under parseMessage: one for indexing and one for the main function
  4. Research more on nameArray.push()

General Idea:

You are trying to loop through the array of “Messages” (not parseMessage) object with proper indexing. Then, via the loop with proper indexing, create strings and PUSH strings in to the new array to return in the function.

1 Like

Take out a set of brackets and get rid of the .text
It worked for me after I did that. Just make sure that you declare and initialize your array to be empty at first. Return the array after that and you should be good.

3 Likes


wut

Can you share your code @Sam1 ?

That worked! Thanks.

I see now my error. I created an empty array, but then tried to assign a placeholder called text.

I see now that I didn’t need placeholders.

1 Like

Thanks yeah, I got it now.

I originally had the thought to put a place holder in my array. Not sure why I went with that.

New coder.

I initially declared my array outside the parseTranscripts function first.
But when the code ran, the function wound up repeating several times.

When I put the array declaration into the parseTranscripts function, it worked fine.

Can anyone explain why?