3. Literally speaking. Code looks 100% correct?


#1

According to this example in another thread:

var james = {
  example(parameter){
    console.log(parameter)
  }
};
james.example("see how");
james.example("this works?")

My below code should be working? Instead I get a "Oops, try again. It looks like your speak method doesn't properly take in a single argument and output the correct string."

var james = {
    job: "programmer",
    married: false,
    speak: function(mood) {
       console.log(mood); 
    }
};

james.speak("great");
james.speak("just okay");

#2

Okay, yeah, sure, that's what codecademy says, have you made any observations yourself about whether the code acts as intended? Have you compared what your code prints, if anything, to what the instructions say should be printed?

If it prints something other than what is described then that's the problem.
If it prints what you think it should print, then maybe you've misread what should be printed and you should double check that.

If you've compared instructions to behaviour of your code and still don't find anything wrong, then drop a link to the exercise and somebody else can compare as well.


#3

Confused. Could someone explain to me why this worked?
My code worked even though I was given a message " reference error: speak is not defined". Thank you!!

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

};

james.speak("great");
james.speak("just okay");


#4

What exactly do you mean by "worked", because you also seem to be saying that it is crashing. I believe you'll have to reconsider how you determine whether it behaves as intended.


#5

code worked as in it let me pass even though I was given a error message.


#6

You can claim that you intend for it to crash, and get passed, and then it would be working because it does as you intend.

If you say that something is working, then you are making that claim.

If you intend something else, then working is probably not the right description of what's going on and you might instead be looking to compare what your code does to what you intend so to figure out what to change to bring intention and reality together.

And if you're asking why something is working, then you should instead read up about that something until you possess most of the knowledge to understand why that something is working. This information is easily available and you do not need to ask about it. If you're missing some specific part and it is difficult to find, then that would be something that is suitable to ask for.

And when you're stating that something is working, you are also saying that you're understanding what it does, because otherwise you are not able to determine that it is working. Saying that something is working and then asking about how, is a very poor way to phrase a question, there is no sensible answer to that. You're asking for information that you are saying you already possess.

Please, read some articles about asking technical questions. There is some very valuable insight in those and can help you ask questions that have answers and in particular invite answering.


#7

Something like this!

var james = {
job: "programmer",
married: false,
speak: function(mood) {
if (mood == "great") {
console.log("Hello, I am feeling " + mood);
}
else if (mood == "just okay") {
console.log("Hello, I am feeling " + mood);
}
else {console.log("No matching responses from: " + mood);}
}
};

james.speak("great");
james.speak("just okay");
james.speak("something");


#8

Your elitist comments aren't needed here. This is a place for everyone to learn and gain experience. If you feel the need to prove how awesome you are do it somewhere else.


#9

"Here is where you went wrong and what you should do instead" is not elitism. That's how the gap is closed.


#10

Your code looks 99% completed. There are two things I would recommend:

1.) If you look at the task requirements, you will notice that the "Hello, I am feeling " part is the same for both arguments. It might be wise to hard code this once in your code.

2.) Try playing around with the ";" inside of the function and see if that works at all.


#11

I have the same question with you. Luckly,I have known that why. A small error of space between ","and "I".


#12

Just help and don't talk so much or talk people down.

here's a code that worked for me:

speak: function(mood)
{
console.log("Hello, I am feeling" + " " + mood)
}
};
james.speak("great");
james.speak("just okay");


#13

This is the shortest and the most effective code that works:

speak: function(mood) {
console.log("Hello, I am feeling " + mood)
}


#14

I 100 percent agree with you.


#15

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.