Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Tried a different approach, wanting someone to help refactor

I tried a different approach, but wanting someone to help me refactor. Possibly using a function or something more streamlined.

let firstName = prompt(`What's your first name?`);
let lastName = prompt(`What's your last name?`);

const fullName = [];

fullName.push(firstName);
fullName.push(lastName);

alert(`The string "${fullName.join(" ").toUpperCase()}" is ${fullName.join("").length} characters long.`);

1 Answer

const person = {
    firstName: prompt("What is your first name?"),
    lastName: prompt("What is your last name?"),
};
let fullName = (person.firstName+" "+person.lastName).toLocaleUpperCase()
alert(`The string ${fullName} is ${fullName.length-1} characters long!`);

Thanks for the help, Victor. Great alternative.