I need help on 11. Function Recap


#1

I put down this and it doesn't do it. I can't figure it out.

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

Please help!


#2

Haha Hi @computergeek2015; The problem is just that your suppose to log the function outside the function. Just put it out and youll be fine!

Your Code :

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

Correct Code:

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

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


#3

it still didn't work and it gave this error. "Oops, try again. Did you create a function called nameString() ?"


#4

Ohhhh! I forgot sorry!

This is the correct code you just had a syntax error on your function!

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

Good now @computergeek2015?


#5

it still doesn't work and now my time is up on the computer. the error message was Oops, try again. Your code doesn't look quite right. Click "Stuck? Get a hint!" if you need help!


#6

ReferenceError: 'greeting' is undefined


#7

Oh gosh another error by me! We named the function nameString so we are suppose to print that name! Sorry its a rough day today!

Must be Correct Code:

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

Please reply if it still dosent work :frowning:


#8

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


#9

Honestly I believe this specific exercise is broken. When I wrote out the code I wrote it this, which does indeed print out the correct answer but says "Oops, try again. It looks like you didn't print anything to the console! Did you remember to console.log() the result of passing your name to the nameString() function?"

This error is just wrong because I am looking at the correct answer being printed out.

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

I then changed it to this, simply moving the console log outside of the function. This print out a false result of "[Function]", but it passes me on the exercise as though it were correct. So I would say you should just skip this exercise, as I doubt it will give you correct information.

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


#10

Thank you for posting this, I'm getting so confused now


#11

Hi there
here is a proper code

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

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

Works fine


#12

@mayers666 Yes that is the correct code but posting informations is better than posting plain code.

A little collection of errors in this threads code:

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

Anything after return is ignored so the console.log is pointless.

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

This:console.log (greeting); prints the function: [Function] which is true but pointless and this:
nameString = ("ComputerGeek2015"); overwrites your function with a new value.

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

here greeting is used without being defined. Same for name here:

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

And finally here:

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

this is the correct function call:nameString("Jon"); but instead of printing it to the console it is never used again and instead the name of the function is printed again leading to the pointless information that this is a [Function]. Hope this helps a bit.


#13

Thanks very much for breaking all of these down. This is very helpful.


#14

Thanks very much. This makes sense.


#15

Thank you so much for the help. It was right!


#16

I tried above and modified it so it actually does print the return sentence to the console:

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

(I had to create another variable called myName which was populated by running the function, then the variable myName is printed to the console.)


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

};
var newString = nameString(prompt("What is your name?"));
console.log(newString);

for a bit of fun.


#18

I'm sorry but this is returning an error


#19

Thanks, I was having trouble but that helped alot. Thanks:)


#20

hi why my code gives a result in the console

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

result:

Hi, I am Rashid
Hi, I am Susie
Hi, I am Bobby
Hi, I am Captain Ahab
"Hi, I am Rashid"