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

JavaScript

Still getting errors

Still getting this error: Identifier 'name' has already been declared I've tried reviewing the code from the instructor's video countless times and still can't see what mistake I've made in this to prevent it from working as it does in the class video.

const name = prompt("What is your name?");

let message = "Hello " + name + ". Welcome to my music site. ";

message += "I'm so happy that you came by to visit, ";

message += name;

message += ". Feel free to come again and listen to more music!";

console.log(message);

1 Answer

MD MONIRUZZAMAN
MD MONIRUZZAMAN
6,130 Points

I assume, you are coding in Chrome Dev Tool. Const is prevention to declare the variable name twice in the Dev Tool,even though you clear the console.In order to prevent this error,you just enclose your code in curly braces it prevents to ressaign your const twice. If you don't want to include curly braces {} use let. Everything in your code is perfect.Just keep goingπŸ˜ƒ

{
const name = prompt("What is your name?");

let message = "Hello " + name + ". Welcome to my music site. ";

message += "I'm so happy that you came by to visit, ";

message += name;

message += ". Feel free to come again and listen to more music!";

console.log(message);
}