Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Print the output of a function using console.log (Javascript) [duplicate]

Tags:

javascript

The following code is meant print the namestring with a name. however, it's not correct.

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

}
nameString("Amir")
console.log(nameString)

What am I not implementing/doing wrong that stops it from displaying the string as well as a name? thanks.

like image 915
user3848245 Avatar asked Dec 19 '22 13:12

user3848245


1 Answers

First mistake in your code is in the line

 return "Hi, I am" + " " + name.

remove fullstop or just concatenate it as below

 return "Hi, I am" + " " + name+"."

and then write

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

check it here fiddle

like image 132
Roshan Avatar answered Dec 22 '22 03:12

Roshan