Stuck at functions lesson 11


#1

Hi, i've been trying to sort this code out but what i got in return was this.


the worst is that it says i can proceed to the next exercise.


#2

var nameString = function(name){
return "Hi, I am" + " " + name // you're missing a semicolon here 
}; // no semicolon is needed here

nameString("Ricardo") // You're missing a semicolon here, and you had a space between the g and opening parenthesis

You don't need the console statement, so you might as well just get rid of it.


#3

It requires the console statement to proceed man. But i don't know if it should only type my name and not the "Hi i am susie" statement


#4

No, it doesn't require it to proceed

And you just type your name.

Have you actually been reading the explanations to the code?

If you had, you would've known that by putting your name for the parameter when calling nameString, it would return "Hi, I am " + whatever your name is.


#5

By the "Use console.log" part of the instructions, it's telling you to nest nameString inside of it.


#6

does it really not need console.log !?


#7

It does, as I just said. You had the wrong interpretation as to what you needed it for. The instructions tell you to put nameString inside the console.log statement, not put the return statement inside of it.

It would look like console.log(nameString('yourname'));


#8

ok, got it now thanks


#9

The instructions really do not make sense to me.

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

I get the correct output (Hi I am Susie) but an error message ("Oops, try again. Hmm, it looks like your nameString() function doesn't return 'Hi, I am Susie' for the name Susie.")


#10

Yeah, I agree that the instructions could be more clear. They are re-tooling the JS course, so hopefully they catch this.

Here are the instructions:

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

So, write a function, use param "name", the function should return "Hi, I am" + " " + name.

I don't think anyone has an issue with that part.

4 Call nameString() by passing it your name, and use the console.log to print the output.

My interpertation:

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

This will allow you to pass the section. However, it does not print correctly. Instead, it simply prints

function:nameString

Which is weird. It seems what the lesson really wants, and what rhyscrypto mentioned above is this:

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

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

So, the instructions should say that the expectation is to call the function and name the parameter when you print the function.


#11

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