In the last exercise, you sifted through Tomás’s watchlist one job at a time: a label here, a filter there, a sort, a search. Each function stood on its own. Movie night needs them working together, in one program that takes the watchlist and tells the friends what to watch.
In this project, you’ll build Tomás’s movie-night picker. You’ll start from a written brief, work out by hand what the finished picker should print, and then implement it in five steps, each one a small function you’ve already practiced writing. Here’s what Tomás has asked for.
Read Tomás’s Brief
At every movie night, someone opens the watchlist, someone else says the film is too long, and half an hour goes by before anyone presses play. Tomás wants a program that settles the routine questions before the friends arrive. Here’s his brief. The picker should:
- Drop the films that are too long. The usual limit is 120 minutes, but on a school night Tomás wants to pass a smaller one.
- List the titles nobody has seen, because a film that’s new to everyone is a strong candidate.
- Find the first comedy that fits, for nights when the group wants something light. If no comedy fits, the picker says so instead of crashing.
- Check whether every film has at least one vote, so Tomás knows whether to chase anyone before the night.
- Print a shortlist of the films that fit, with the most votes first. When two films have the same number of votes, the shorter one comes first, so the night ends earlier.
Steps 2 to 5 all work on the films left after step 1, because there’s no point suggesting a film the group won’t have time to finish.
The picker reads the same watchlist you’ve used throughout the course, with one change. Lucía has now voted for Arrival, so it has 4 votes instead of 3. If you’d like to build the picker on your own computer as well as in the exercises, create a file named picker.js and start it with this array: