Scriptdrill

Level 1: Basics Exercise 3 of 45 Free

Full names

A JavaScript exercise from Scriptdrill. Solve it with a code editor in your browser that runs your function against example and hidden tests, and it is checked the moment you submit.

The task

Each user looks like `{ first, last }`. Return an array of full names: first and last joined by one space. Some people have no last name (an empty string, or no `last` field at all); for them return just the first name, with no trailing space.

What this exercise teaches

map turns each user into one string. Checking user.last for truthiness covers both the empty string and a missing field, which is undefined.

A hint if you get stuck

Map each user to a string. Decide with a condition whether to add the space and the last name: `user.last ? ... : user.first`.

Try it now, no account needed

This exercise is free. Open it on the practice page, solve it, and get instant feedback with a hint and a worked solution after two tries.

Open this exercise

More exercises in Basics