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 trialkols
27,007 PointsMy Solution to "The Student Record Search Challenge" incl. Add'l Challenge Requirements
I'm including a link to my solution to this challenge below, as it was definitely a tricky one! I've only used code that we have learned up until this point, albeit there are probably much cleaner ways of doing this.
In addition to the solution Dave already presented, at the end of the video he asked us to further edit the script so that it would:
- Display when a user searches for a name, but no results are found.
- Show all results for multiple users with the same name (e.g., multiple students with the name Dave).
Furthermore, I made sure that the solution below avoided printing duplicate results if you search a name twice (or more); e.g., if you search 'Sam' multiple times, the corresponding result(s) of "Not Found" should only be displayed once.
I implemented some of the same code he showed a little differently, and added some additional minor formatting to make the printed results a little clearer, but the above requirements should be met.
Keep in mind, you'll have to search a few names and then make sure to type "quit" to exit the prompt. (Note: I kept the names Trish, Jody and Dave, with the latter [Dave] being used for three of the students; you will need to type in these specific names to verify that the requirements above are working properly.)
You can test this solution out by viewing my snapshot of this Workspace, and clicking on the 'Fork Snapshot' in the top right corner of the page. It will open a workspace window as usual and you preview the code as you normally would.
If you notice any errors, please leave a comment below. I'm sure this solution could certainly be cleaned up and/or improved upon, so feel free to post any refactoring suggestions or alternate ways of achieving the same thing using code we've learned up until this point (or beyond).
1 Answer
KRIS NIKOLAISEN
54,971 PointsLooks good. I made one minor change to handle if a user clicks cancel
if (searchTerm === null || searchTerm.toUpperCase() === "QUIT" ) {