Help with 3. Introductions to Functions in JS


#1

What should I have done cause I dunno what I'm doing.

Instructions are:

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.

My goal is to write:
Hi, my name is Bill

What I really wrote was:
Hi, I am undefined

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

var Bill = nameString()
console.log(Bill);

#2

First off, you forgot a semi-colon here.
Second, what you have right now is taking in a variable of Bill instead of a string. Try putting quotes around the inputted parameter when you're calling it


Try

var Bill = nameString('Bill');

or just

console.log(nameString('Bill'));


#3

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