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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Keith Griffin](https://secure.gravatar.com/avatar/3e51b7c4873e4d25fbb67df612681ea1?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Keith Griffin
4,833 PointsMore efficient way of writing the code?
I get that this is supposed to demonstrate boolean values but it's hard for me to wrap my head around when there is a more efficient way of writing the code. isn't this better?
const number = 6; const guess = prompt("Guess a number between 1 and 10");
if (+guess === number) {
console.log("You guessed the right number!");
} else{
console.log(Sorry the right answer is ${number}
)
}
1 Answer
![Robert Gulley](https://uploads.teamtreehouse.com/production/profile-photos/11554217/micro_me.jpg)
Robert Gulley
Front End Web Development Techdegree Student 10,722 PointsHi Keith -
Yes, the code you wrote is more concise. As you noted, the purpose of this particular video is to teach about Boolean values, and that was why the code was written the way it was.
Make sure to use your template literals and remember your semicolons, though. Your code as is will throw an error. Try re-writing the code in the else statement like this:
console.log(`Sorry the right answer is ${number}`);
Happy coding!