Discover how to build a movie database display using JavaScript and Python, making it sortable by name, duration, and year. Learn the process from Brian McLain, an experienced instructor at Noble Desktop, New York City.
Key Insights
- Brian McLain, the instructor of JavaScript and Python programming at Noble Desktop, gives a step-by-step breakdown of building a movie database display.
- The tutorial focuses on creating an array of movies that can be sorted by name, duration, and year.
- The first step introduced is to add a new property to the array of movies so that the total number of minutes is not displayed in its raw form.
- Using JavaScript, Brian shows how to set up a loop through the movies array, extract the movie's mins property, and calculate hours and remaining minutes.
- A new key is then added to the movies object to display the movie's duration in a more user-friendly format (e.g., '2h 14m' instead of '134 minutes').
- The video series aims to guide viewers through rendering the movie database display and implementing a sorting feature in subsequent lessons.
Build a Sortable List
-
Store Data as an Array
Each movie is an object: { title, year, rating }.
-
Sort with a Comparator
arr.sort((a, b) => a.year - b.year) — number sort by year.
-
Render to the DOM
Map sorted array to <li> elements and inject into a <ul>.
-
Add Sort Buttons
Click handlers re-sort by different keys, then re-render.
Video Transcription
Hi, my name is Brian McLain. I'm an instructor of JavaScript and Python programming at Noble Desktop in New York City.
In this video and in the ensuing couple of videos, we're going to look at how to build a movie database display. So I have a set of movies, and we want to load them up into the browser and have them sortable. Here they come in alphabetized by name, but we can also sort them by duration and by year.
In this first video, we just want to add a new property to our array of movies so that we don't have to display the total raw number of minutes. If you look over at IMDb, here's Black Panther at 2h14m—that's the format we want. We don't want it to say 134 minutes. That's because our dataset has an array of objects and there's a property called mins where we're drawing that information from. We also have name and year.
So the first thing we want to do is implement that fix. We're going to set up a loop through the movies array. We're going to say, let I equal zero. I is less than movies.length, I plus. Every time through, we want to grab the movie's mins property.
So I'm going to say let mins equal movies[i].mins. Then, we're going to get the hours out of that by dividing mins by 60 and rounding that down. We'll say let hours equal mins divided by 60 and to round all that down, we'll wrap it in Math.floor which returns the takes whatever's in the parentheses and rounds it down.
Then, we're going to use the modulus operator which goes between two numbers and returns the remainder of the first divided by the second to get the remainder of minutes. We'll say let remainder minutes equal mins mod 60. So, in the case of Black Panther, that'll give you a 14. Then we're going to add a new key to our movies object. We're going to say, movie[i].ourMin = `${hours}h ${remainderMin}m`. That should do it.
So this is on a loop, right? So every time to the loop, we'll get a new property called ourMin. So let's log all that array of objects to the console to see if we do have that new ourMin property. Come over to the console, we have an array and there it is—there's a new property. Whoa, and we have a bug because I put the dollar sign inside the parentheses instead of outside, so we'll fix that real quick. Yep, back, refresh, open and we're all good and Black Panther is now 2h14m.
So stay tuned for the next video where we render everything and then the video after that, we're going to implement the sort. In the meantime, till then, thank you very much. Once again, I'm Brian McLean with Noble Desktop in New York City.
Video Transcription:
hi my name is Brian McLean I'm an instructor of JavaScript and Python Programming at Noble desktop in New York City in this video and in the ensuing couple of videos we're going to look at how to build a movie database display so I have a set of movies and we want to do is load them up into the browser and have them sortable so here they come in alphabetized by name but we can also sort them by duration and by year but in this first video we just want to attend to one detail we're going to add a new property to our array of movies so that we don't have to display the total raw number of minutes if you look over at IMDb here's black panther at 2h14m that's the format we want
we don't really want it to say 134 minutes and the reason it's doing that is because that's what our data set has we've got an array of objects and there's a property called mins and that's where we're drawing that information from we also have name and year so the first thing we want to do we're going to implement that fix so we're going to set up a loop through that movies arrange so we're going to say for let I equals zero I is less than movies dot length that's that big array of objects you just saw I plus plus and every time through what do we want to do we want to grab the move the mins property so I'm going to say let mins equal movies I dot Min and then we're going
to get the hours out of that by dividing mins by 60 and rounding that down so we'll say let hours equal mins divided by 60 and to round all that down we'll wrap it in math.floor which Returns the takes whatever's in the parentheses and rounds it down and then we're going to use the modulus operator which goes between two numbers and returns remainder of the first divided by the second to get the remainder of minutes so we'll say let REM men's remainder minutes equal men's mod 60. so in the case of black Panther that'll give you a 14.
then we're going to add a new key to our movies object we're going to say moviesi dot our Min we'll call it equals and we'll use string interpolation to just say hours followed by an h space remainder mins followed by a Min uh M and that should do it so this is on a loop right so every time to the loop we'll get a new property called hour Min so let's log all that array of objects to the console to see if we do have that new our Min property come over to the console we have an array and there it is there's a new property whoa and we have a bug because I put the dollar sign inside the parentheses instead of outside so we'll fix that real quick yep back refresh open and we're
all good and black panther is now 2h14m so stay tuned for the next video where we render everything and then the video after that we're going to implement the sort in the meantime till then thank you very much once again I'm Brian McLean with Noble desktop in New York City bye-bye
