JavaScript Introducing ES2015 The Cooler Parts of ES2015 Default Parameters

Vladimir Plokhotniuk
Vladimir Plokhotniuk
5,464 Points

Introducing ES2015, dont working the same code

hi, i copied the code in WebStorm, but in console.log i have this " Good undefined, undefined! " Then i cannot working from this beginning step ( What is wrong?

function greet(name, timeOfDay) { console.log(Good ${timeOfDay}, ${name}!); } greet()

4 Answers

Hannah De Los Reyes
Hannah De Los Reyes
18,289 Points

You are missing the back-ticks around Good ${timeOfDay}, ${name}!

Also, like others have said, you need to pass in arguments when you call the function.

Steven Parker
Steven Parker
170,317 Points

The back-ticks were used in the question, but were not shown because the code is not formatted. Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

function greet(name, timeOfDay) {
 console.log(`Good ${timeOfDay}, ${name}!`); 
} 

//You need to pass the parameters to the function, like this:
greet("Paco","15:00");
Steven Parker
Steven Parker
170,317 Points

The "greet" function shown here is designed to take two arguments, and include them in the display.

But when you call it without arguments ("greet()"), the system displays "undefined" in the places that the values would be shown.

So when you call it, pass it some arguments to use. For example:

greet("Vladimir", "morning");
Vladimir Plokhotniuk
Vladimir Plokhotniuk
5,464 Points

Thanks to everyone. I entered another character, like " ' " instead of " ` ". I did not know that they affect the function differently.

Steven Parker
Steven Parker
170,317 Points

I could tell that you had used backticks correctly by the way the font changed. To have code appear correctly, see the instructions I mentioned in my previous comment.