I am stuck on this exercise


#1

**** I don't understand what I'm doing wrong in this exercise, please help. This is what I typed:

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

This what it keeps telling me:

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

This is the instructions:

Instructions

Write a function called nameString()
It should take name as a parameter.
The function returns a string equal to "Hi, I am" + " " + name.
Call nameString() by passing it your name, and use console.log to print the output.

#2

2 Problems, First it can input any name it wants so it has to return :smile:

return ("Hi, I am" + " " + name);

Secondly when you call it at the end you just need this to call the functions:

nameString(Susie);

Hope it helped! If it didnt please reply saying so!


#3

The function is expecting a parameter that it'll use in it's function. So let's dissect a function real quick.

var exampleFunction = function( parameter ){ //creating a variable function 
    return parameter; //utilizing the parameter 
};
exampletFunction(parameter); //giving the function a parameter to run.

Now let's change around your code to incorporate the functions parameter and see what happens.

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

So the computer reads this.

nameString("Bobby"); //Ok this is the parameter for nameString

var nameString = function( "Bobby" ){ //Ok so now the parameter is now in the function

console.log("Hi, I am" + " " + "Bobby"); /*Finally, it takes the parameter and puts it
                                           into the text*/

#4

I believe that I did what you suggested but it still isn't working; apparently I'm still misunderstanding something. This is what I put:

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


#5

Hi lolman:

I tried your suggestion and have not been successful. you have console.log after var nameSting = function. This is not what the instructions asked for, so I'm still confused. This is what I have now:

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


#6

alexiabiz, you have misunderstood what both of them told you, your code hasn't changed. You are only returning only the string, you need to put your parameter (a parameter is a variable) in the string. If you do not do this, it won't return anything different no matter what you put in nameString();

return ("Hi, I am"+""+name);

if you do not understand this, or what was said above, you must learn what it is before you continue. To learn how a basic function works go here before continuing with any of the lessons.


#7

Hi emgo_dev

A function is something that is executed so that it isn't repeated over and over again. You call on it to automatically type perform or type out something. That's not the problem the problem is that despite me trying to follow the directions word for word it's not letting me pass. I typed in ("Hi, I am" + " " + "Susie") isn't this what I was supposed to do? I typed the parameter in the string. "Susie" is the parameter isn't it.


#8

emgo_dev

Nevermind I finally got it:

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

Thanks for your help.


#9

:wink:
No one can help you at all if you're not willing to listen. It took three people to tell you the same thing.


#10

Emgo_dev:

Did you not read where I said I got it solved? It's not that I wasn't willing to listen, I was not understanding your explanation, sometimes you have to understand when someone is new at this stuff they may not understand what you are talking about. There is no need to get impatient and nasty to people when they ask for your help. You are way more experienced than they are. You may have a full understand because have already been there and done that but I don't. I got through most of this stuff without asking for help but when I get stuck and I ask for help I need someone there is going to be patient and understanding; but you have a nice day.


#11

If you had said don't put the a persons name in the string and just put the variable in there I would have understood what you were talking about, But from past exercises I was taught to put a person's name in the string so you should understand my confusion.


#12

I hope the rest of the course goes well.


#13

You're absolutely right! No one should be treated like that just because they're asking for help. Don't hesitate to ask for help because there're so many out there who will help you respectfuly.


#14

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

I think it shoud be

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

so the nameString then give the value of susie in the return