Challenge 5 Megathread

Welcome to challenge #5!

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

3 Likes

Day 5, let’s do this!

4 Likes

It occurred on day one. But look on the bright side, you can sleep sooner.

1 Like

I tried Challenge #5. It says I successfully added the job to the astronaut object, and successfully returned the astronaut, but I keep getting an error that I haven’t returned the entire object with all properties, including the job. Also, when I submit the job for Chris Hadfield the error console says it expected the job for Julie Payette, and vice versa.

1 Like

Things that pop into mind when I read your question:

  • are you altering the existing astronaut, or creating a new one? (you don’t need to do the latter, but if you are, be sure to copy over all of the other values)
  • are you hardcoding so that it only works for a particular astronaut? You need to keep the code flexible, so that it will work with anyone.

Here is my code and I don’t think it’s incorrect. I believe the reason for error is that there is unwanted value embedded within this platform


const Astronaut = {
firstName:“Chris”,
lastName: “Hadfield”,
nickname:“Space Oddity”,
prefix:“Astronaut”
}

function addJobToAstronaut(Astronault){
Astronaut.job = “Shuttle DJ”
return Astronaut;
}

console.log(addJobToAstronaut);

Seriously, who is Julie? her profile was never mentioned in instruction

Have the same problem!

Hello there,

The object to be used in the function is passed in as astronaut and the job to be assigned is being passed in as job in the original function provided in the code editor. So no need to rewrite the function and objects, you can just add the new code in the space between the two comments of the original code.

Don’t overthink the challenge. It states simply to add a property to the object. Let the parameter “job” passed on to the function be the assigned value of the new property.

Hint -- spoiler alert

object.newProperty = “String which will be assigned to the newProperty”

3 Likes

const addJobToAstronaut = (astronaut, job) => {
const exampleAstronaut = (firstName, lastName,nichName,prefix,job){
this.firstName = firstName;
this.lastName = lastName;
this.nickName = nickName;
this.prefix = prefix;
this.job = job;
}
return exampleAstronaut// Code here!

// Remember to return a value!
}
const exampleAstronaut = {
firstName:“Chris”,
lastName: “Hadfield”,
nickname:“Space Oddity”,
prefix:“Astronaut”
}
const newJob = ‘Shuttle DJ’
addJobToAstronaut(exampleAstronaut,newJob)

can somebody help me? it says “Unexpected token {”

It was easy, don’t do too much on that one.

This challenge is a two-line “job”. :wink:
Just create a new property for the object, and pass it the value contained in the parameter job.
Then return the object and “Bob’s your Uncle!”

4 Likes

Lol, I was about to ask here about an issue but decided to play around as in the few days I was often adding an extra word or something that made the whole thing fail… and it worked. I’d suggest to anyone having issues looking up how to add a parameter to an object if you are unsure on how to tackle this

3 Likes

Now it is saying “firstName not defined…”

I know it is a two line job but what it maybe easy for one person it is not for everybody.

4 Likes

It’d be nice to be able to see exactly what the “user” is typing in for each test, and how your code is being processed.

1 Like

I think you can assume the “user” is putting in:

addJobToAstronaut (Hadfield, Shuttle DJ) //or something similar

and your code’s purpose is to accept “Shuttle DJ” as the value for astronaut.job

1 Like

Try to assign a new property, of appropriate name, to the object that was given.

This is how you assign a new property to an existing object:

existingObject.newProperty = Put something here that is appropriate for this challenge.

4 Likes

For me, knowing nothing about Javascript before starting these challenges, my problem was wondering how to get the code to accept whatever the “user” put in the parentheses after the comma as the value for astronaut.job

I agree with your statement. The process of learning involves thinking, struggling a little bit, researching, trying things out, and this is what makes it fascinating. You are on the right track.

2 Likes