Showing error!


#1

hii,i am stuck and i reaaly dont knw where i want wrong.my code is-
var nameString = function (name ) {
return "Hi,I am"+" "+name
};
var intro=nameString('Arushi');
console.log(intro);

and its showing error-
Oops, try again. Hmm, it looks like your nameString() function doesn't return 'Hi, I am Susie' for the name Susie.
i am not able to rectify it.

`


#2

Why are you setting var intro? Why not just console.log(nameString("NAME"))

You'd be printing what the function returns.


#3

okk,but bt wats wrong in dat...?


#4

Well strictly from a coding logic standpoint, why would you set a variable to something that is already set? You have a whole extra line to do that. This is simple code, but in more complex code, you might end up writing a lot of extra lines. One of the reasons it may not be working though is that the instructions tell you to write one function that logs, and does not return. Then call the function with a parameter.


#5

okk...but den also its showing d same error...


#6

It might be the codecademy interpreter, because the instructions told you to write a functions that logs, and does not return. That way you can just call the function and it will log.


#7

This is the format you should use for this little code.

var firstvariable = function(name) {
    var secondvariable = name;
    console.log(secondvariable);
};
firstvariable("name")

Follow this little pattern and your code should work once realigned with a reasonable structure


#8

instructions-
The function returns a string equal to "Hi, I am" + " " + name
the instruction says to return...


#9

What lesson are you on? I may have assumed the wrong one


#10

functions recap...in itroduction to function in js


#11

Yes my bad. So your first part is fine

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

However, your second part is wrong. You just need to console.log the variable and the name inside of that. For example:

console.log(variable("name"));

Sorry for the confusion!


#12

its okk...but its not working...it is again showing d same error...


#13

Paste your code and let me see then


#14

here it is-
var nameString = function (name ) {
return "Hi,I am"+" "+name
};
console.log(nameString("Arushi"));


#15

It is your formatting in your spacing that is leading you astray here. Copy and paste this spacing in and it should pass. I just passed it in my lesson with this so you should be good.

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

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

#16

Sorry it looked like you were on 3.


#17

Yeah I thought the same thing lol Thankfully I think we have righted the ship


#18

yap...u were right...i just hope it is codecademy interpreter only...or spacing formatting is also checked...?
thnxxx... :slight_smile:


#19

Sometimes spacing can throw of the codecademy interpreter. It is very important in some languages like Python. Plus if you learn to space your stuff out right in languages that don't require it, it will make it more readable.


#20

Yes, one of the things I had to learn is you can't just do whatever spacing or line up you want. It is not so much in java-script as in other computer languages like python but you do have to organize your code properly or even if its right it won't work. Hopefully your other coding will be a little less confusing and good luck!