Concatenation in JS functions

1

0

First question here. I am doing Codecademy's JS basics course and have run into a question concerning concatenation in functions.

I have:

var greeting = function(name){

console.log("Hello, "+"" +name);

};

Obviously, when I call this function with:

greeting("Chris");

I get, Hello, Chris

What if I wanted to spice that up a bit and have the output say, Hello, Chris. How are you doing today?

I tried several different things that all lead to syntax errors. For example:

var greeting = function(name){

console.log("Hello, "+"" +name "." ""+" How are you doing today?);

};

So, the question is how do I join the next strings after including the function output following the initial string? I don't know if that sentence makes any sense. So, In plain english, how do I get the period and the subsequent question in there after the output, Hello, Chris?

Thanks for any help!

Fully

Posted 2015-03-30T15:41:15.050

Reputation: 11

Question was closed 2015-03-31T07:35:39.433

Issues specific to programming and software development are off topic, see What topics can I ask about here?. Try [SO] but please first read How do I ask a good question?.

– DavidPostill – 2015-03-30T17:15:46.833

Answers

1

You're missing a + operator.

console.log("Hello, "+"" +name "." + ""+" How are you doing today?);

You also have a couple of empty strings that could be removed:

console.log("Hello, " + name "." + " How are you doing today?);

heavyd

Posted 2015-03-30T15:41:15.050

Reputation: 54 755

1

Although you may know that here is not the place to ask such questions but I have to tell you that, javascript concatenation uses the join() function which uses the comma , for joining if you dont provide it any arguments (as you provided "")
Use " " (quotes with space between) instead of ""

TechLife

Posted 2015-03-30T15:41:15.050

Reputation: 822