settingsAccountsettings
Menusettings

Q: Print Hello, JavaScript! in the console

+1 vote

Write a JavaScript function (code) that can receive a name as input and print a greeting to the console.
The input comes as a single string that is the name of the person.

Examples:

Input:
Pesho

Output:
Hello, Pesho, I am JavaScript!


Input:
Bill Gates

Output:
Hello, Bill Gates, I am JavaScript!

The output should be printed to the console.

asked in JavaScript category by user golearnweb

1 Answer

0 votes
function printGreeting(name) {
    console.log("Hello, " + name + ", I am JavaScript!");
}
printGreeting("Bill Gates");

We need to concatenate three strings – the two static parts of our greeting and the name of the person in the middle. We can do this by simply adding the three strings with the addition operator. Since this is an operation which returns the concatenated string, we can directly perform this expression in a call to console.log(). Note the space at the end of the first string.

answered by user ak47seo
...