0

New to coding and new to this website. I did try to search for the answer to my question in the previously asked questions section but they all seemed way above my pay-grade. So, below is my code I'm using and my question is below it. (btw I'm using codeacademy to learn if this stuff looks really basic :/)

var greeting = function(name)
{
    console.log("Great to see you," + " " + "name");
};

greeting("Matt");

My question, I cant figure out what i'm doing wrong (if anything). I was under the impression that in the line:

greeting("Matt");

it would populate the name I entered there and tether it together with the other part of the string I declared in the "var" as shown below:

 "Great to see you, Matt"

Unfortunately it does not. It is merely printing to the console "Great to see you, name". I feel like I needed to declare something to recognize the input I put below but the example given as a guide doesn't do this and it prints out properly as "Great to see you, Emily" in the example.

Any help would be greatly appreciated. Additionally, I tried my best to format this in the most readable way possible. If you have any tips for future questions and discussions it would be appreciated!

4
  • 2
    console.log("Great to see you," + " " + name); Commented Feb 17, 2017 at 7:31
  • Remove quotes to show the passed argument. "" are used to depict strings Commented Feb 17, 2017 at 7:32
  • You are printing string "name" instead of a variable! use name instead Commented Feb 17, 2017 at 7:32
  • You already know about strings (e.g. "Matt"). How should JavaScript know that if you use "name" you want to get the value of the variable name instead of the string "name"? It cannot. Commented Feb 17, 2017 at 7:46

3 Answers 3

1

Your name is in "", So it is as text, not variable. Just remove the "" around the name.

var greeting = function(name)
{
    console.log("Great to see you," + " " + name);
};

greeting("Matt");

Sign up to request clarification or add additional context in comments.

Comments

0

So you want to call name, which is a variable that stands for the string "Matt". Right now, you are calling the string "name". Get rid of the quotes!

On another note, you can just add the space to the end of the first string and not have the floating " ".

Comments

0

remove the double quotes "" in name variable in your console.log(). If you put a double quotes to it, it will be interpreted as string

var greeting = function(name)
    {
        console.log("Great to see you, " + name);
    };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.