Stuck with the wrong kind of output


#1


https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/3?curriculum_id=506324b3a7dffd00020bf661#


undefined


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


#2

Right now your sixth line is calling nameString without any parameter. I think that's what is causing the undefined error.
Try dropping display from your code entirely and then calling nameString("max") directly inside of console.log.


#3

You have a lot of unnecessary/confusing code going on, simplify it:

var nameString = function (name) { // defining nameString function that accepts a (name) parameter
    return "Hi, I am " + name; // returns a string with "Hi, I am MFX88"
};

console.log(nameString("MFX88")); // prints out function nameString of MFX88 === "Hi, I am MFX88"

or, if you want to use a predefined variable:

var myName = "MFX88"; 

var nameString = function (name) { // this "= function (name)" may be a bit confusing, but it's taking whatever parameter (value, boolean statement, strings...etc) that was passed into it from the call below and temporarily storing into to a local name variable
    return "Hi, I am " + name;
};

console.log(nameString(myName));

#4

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