11/13 is correct, but still gives me an error


#1

var nameString = function (name) {
return "Hi!, I am" + " " + name;
};
console.log(nameString("Suise."));

the error is "Oops, try again. Hmm, it looks like your nameString() function doesn't return 'Hi, I am Susie' for the name Susie"

I've searched the Q & A forums for about 20 minutes and it all says it should end like this.


#2

I had the same problem. Try this code

return "Hi, I am " + name;


#3

I have the exact same problem and i still can not work out why


#4

I refreshed the page and it solved the problem :smiley:


#5

First of all, you wrote Suise, not Susie.


#6

tried this and it still came back with the same error


#7

tried that and it still doesn't work


#8

changed that and I still have the same error.

and the strange thing it, it tells me that I'm not returning that line of text when the return reads as follows, "Hi!, I am Susie" and I believe that's what it's asking for,


#9

var nameString = function (name)
{
return "Hi! , I am" + " " + name;
};
nameString (Aaronthekill);
console.log (nameString);

try that!


#10

I'm just going to explain it, since @mara15 already said the correct answer....

As you probably know, Codecademy is picky. Right? I got that wrong ALOT because of one reason:

SPACING

In returning the string, you have to do the string correctly with the spacing to do it. It may seem outrageous, but it works, right? :smiley:

Hope it helped!:smiley:


#11

var nameString = function (name)
{
return "Hi, I am" +" "+ name;

};
nameString(Mathew);
console.log(nameString);

i'm unable to get the output. need help.


#12

Mattew must be a string!

var nameString = function (name) 
{
return "Hi, I am" +" "+ name;

};
nameString("Mathew");
console.log(nameString);

See if it works now.


#13

Ok, here is the right answer:

var nameString = function (name) {
	return "Hi, I am" + " " + name;
	nameString("Susie");
}

console.log(nameString);

#14

Ok here is a message at all of you:

It's really appreciated that you want answer the question and I've seen really good answers in the forum, but if you do so. Please do not post solutions with nothing but an imperativ tone: "Do it like this". There are often many ways to do it and I hate to say this but none of the codes posted here marked as "the solution" is actually correct. If you answer a question try to find the error and give some hints how to fix it. And if you post your code at least explain a bit what you think is the critical point in it and what the concept is. The least best solution is that the OP copy pastes your solution doesn't understand what is actually wrong and ends up frustrated because he/she fails on further exercises because the basics are missing. Thank you.

@aaronthekil From what I can see your problem is just the extra ! after Hi. The problem is that some exercises check for sentences or parts of sentences in a way like this userInput.subsrt(...) == "Hi, I am ".Warning: This is pseudocode that is not how it is done just to give you an idea of how it might be done. So if you're sentence differs from what is expected you get an error. As @ragezapper partially implies. As your code looks almost perfect also what @dracoslayer implies to refresh the page might be an option that works. But as said here there is a real problem so it won't.

@all Susie is just an arbitrary name you could use any name here that you want. What happens is just that the code runs through some test and Susie seems to be the first name in this test so if it is correct you don't even recognize anything if it is not it tells you that it expects the output "Hi, I am x" for the function call nameString(x). Why x is Susie. Idk maybe it's the authors girlfriend maybe it's just random anyway this does not matter any trying to trick the exercise by using Susie does not help.

Last but not least:

nameString (Aaronthekill);
console.log (nameString);

This is a commom problem because many don't seem to understand that call and console.log only mean the order in which it is done but not that this should be two statements. If someone knows a better wording please go ahead. Still what is meant is what the OP used:

console.log(nameString("Suise."));

What happens here:

     nameString (Aaronthekill);
     console.log (nameString);

is that you call the namestring function get the result and dump it as it is never used again. Also as @scriptdolphin you need to make your argument a string. So it would rather be

nameString ("Aaronthekill");

otherwise you would confuse it with a variable. And:

console.log (nameString);

this is just printing the function name so what you see on the screen should be [Function] because well nameString is a function. To get the expected string you need to call the function with an appropriate argument (the value in () after the function).

As you can see not all of your answers are wrong and as said answering the questions is well appreciated but please try to do it in a less imperative and more helpful way:
Thank You!


#15

Hi, Haxor. I'm so sorry, I was just trying to help, from now on I will only answer with hints. Sorry again.


#16

Never fear! Nothing too complicated, simply a matter of following the instructions. It's much easier to understand when you take things one step at a time. True, there can be many approaches to the solution but if you follow each of the instructions, this is the specific way that the instructional module is prompting you to input an answer.

  1. Write a function called nameString() (per former instruction, this is how you write a basic function, by writing out var followed by something for you to use as a function).
    var nameString

  2. It should take name as a parameter (note the lingo, parameter basically means what you need to put in the parenthesis).
    = function (name)

  3. The function returns a string equal to "Hi, I am" + " " + name (this instruction is requesting that you specifically use a return string with these exact words).
    {
    return "Hi, I am" + " " + name;
    };*

  4. Call nameString() by passing it your name, and use console.log to print the output (for some reason, though they don't specify a name for you to use, the error messages will indicate that they desire you to use the name Susie... the specification of this instruction is that you use the consol.log string).
    console.log(nameString("Susie"))

Complete:

var nameString
= function (name)
{
return "Hi, I am" + " " + name;
};
console.log(nameString("Susie"))

#17

You must take out the ! in Hi!


#18

I'm getting an error for not using the name "Susie", however that was never in the directions. I think this is an error in the system that's not allowing me to pass my name. Am I crazy or am I correct?

Thanks for all the help :smile:


#19

It's probably not about "Susie" but about the extra space in your output message:
Either use +" "+ or a space at the end of your string but not both at the same time.
Also console.log(nameString) does not work as expected, I tried to explain this above. And last but not least using anything after return is just ignored as return exits the function so your function call is never even reached. Also calling a function inside itself can cause a stack overflow (recursion), so better move this one outside. And last but not least it helps if you post the code instead of a screenshot so that one could run it.


#20

try nameString("Mathew"); instead of nameString(Mathew);