3. (Objects II) Literally Speaking method confusion


#1

Hi community,

I'm not sure what I'm doing wrong in this method practice.

I've been stuck on this problem for hours now. I've even gotten to a point where the console doesn't print the write answer however CodeCademy still gives me the "Success" pass.

Here is my code:
var james = {
job: "programmer",
married: false,
speak: function() {
console.log("Hello, I am feeling" + speak)
}
};
james.speak("great");
james.speak("just okay");

Does anyone know the correct answer for this?
I'm clearly not understanding how to incorporate the 'mood' per the hinted suggestion.

Thanks for any feedback!
Alex


#2

Hi @calialejandro,

If it may help, please see the code sample below.
Unfortunately I do not have access to that lesson, so I am unsure of the requirements, none the less going simply off the context of your question, it looks like the main issue is that you do not have any parameters available to actually passing anything into the "speak" method, instead you seem to have accidentally passed in the name of the actual function; now you could just as easily have used the term "speak" as your param, but in this case to reduce confusion and better describe what your function is trying to do we will use the term "myMood" in this example.

Hopefully this will help get you where you need to be in your lesson, if it may also help the following is a link t explanations on Functions, though I feel if you are this far in CC you may not need it as much :slight_smile:
If there is anything unclear or you have more follow up questions feel free to reply and someone will try to answer as soon as they can :slight_smile:

Basic Function Notes

var james = {
    job: "programmer",
    married: false,
    speak: function(myMood) //add a param that can be used in the functions code block
    {
        console.log("Hello, I am feeling" + myMood) //use the param here in the actual code block
    }
};
james.speak("great"); //here you are passing an argument to the function
james.speak("just okay"); //it will now be used by the param you supplied

#3

Hi @mike_in_training , thank you very much for taking the time to help me!

While CC still didn't print out the console.log message to the terminal as it asks...it does suggest that I am submitting a successful answer. I even ran this code in my desktop terminal and it seems to print out fine there so maybe there's a bug on this lesson which from looking at other forum threads appears to have changed in the last month.

If you are interested in checking it out, it's in the JS course, section Objects II, step 3/30 (embarrassingly early to be so full of struggle, I know, hahaha)

Thanks again!
Alex


#4

Ahh my apologies.... I thought this was Unit 8, Chapter 3, which is just a quiz called objects II D'oh! :laughing:

That said I had a gander over it, otherwise if you want to take a screenshot with your end result I can try to see if there is anything else we missed, but the fact that you A) put hours in to resolve it, B) stepped up and asked for help and C) took it one step further to test it outside CC suggests to me that you should not be embarrassed at all, you did a fantastic job actually! :slight_smile:

So using the code above the only one thing I found was the awkwardness of CC and the way it must be written to work.
The issue when I tested this just now is the CC console that marks the answer does not recognize the fact there is no space between the param output and the sentence you wrote so simply adding a space should hopefully work for you.

If the comments below are too much it just means we need to add a space between the word feeling and the final double quote "

so "feeling" becomes "feeling -space here- "

Let me know if you still have it in you to fight some of CC's quirks again and try that out lol :wink:
If not but you want to persist please do post a screeny, we may even be able to report it on to a mod if it is a bug and you'll have added a D) to your list along with an E) :slight_smile:
D) done damn well and been polite in the community
E) you've given back yet a little more by helping others and reporting a bug, therefore reducing the frustration others my experience :wink:

var james = {
    job: "programmer",
    married: false,
    speak: function(myMood) //add a param that can be used in the functions code block
    {
        console.log("Hello, I am feeling " + myMood) //use the param here in the actual code block: added a space between feeling & the " EG: "feeling " not "feeling"
    }
};
james.speak("great"); //here you are passing an argument to the function
james.speak("just okay"); //it will now be used by the param you supplied

#5

Here is the correct code for this topic inside of the speak method:

speak: function(mood) {
console.log("Hello, I am feeling" + " " + mood); //I noticed in this line that CC only accepts the string if the quotations are in the middle of both plus signs with a space in between. It will not accept the string if there is no space in between the quotations. Very picky
}