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 JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

Gyorgy Andorka
Gyorgy Andorka
13,811 Points

A cleaner solution for the cancel button issue using ternary expression

search will be set to lower case once and for all (don't have to remember to do it every time when doing some comparison) while the problem of calling a string method on null is also eliminated, in one line:

while (true) {
    let search = prompt('Type a name to display student report, or type "quit" to end.');
    search = (search === null) ? 'quit' : search.toLowerCase();
    ...

About the ternary operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

Steven Parker
Steven Parker
229,744 Points

The Ternary operator is also covered in Treehouse courses.

There may be others, but in the Exploring JavaScript Conditionals workshop it gets its own video: Ternary Operator