Skip to content

Commit 3077c40

Browse files
committed
feat: day 17
1 parent 6654d17 commit 3077c40

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

017-movie app/index.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<link rel="stylesheet" href="style.css" />
7-
<title>Movie App</title>
7+
<title>My Movie Finder</title>
88
</head>
99
<body>
1010
<header>
11-
<h1>Should I watch it?</h1>
11+
<h1>My Movie Finder</h1>
1212
<form id="form">
13-
<input type="text" placeholder="Search" id="search" class="search" />
13+
<input
14+
type="text"
15+
placeholder="Search for a movie..."
16+
id="search"
17+
class="search"
18+
/>
1419
</form>
1520
</header>
1621
<main id="main"></main>

017-movie app/script.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,37 @@ const form = document.getElementById("form");
1010
const search = document.getElementById("search");
1111

1212
const getClassByRate = (vote) => {
13-
if (vote >= 7.5) return "green";
14-
else if (vote >= 7) return "orange";
13+
// Adjust Rating Color Thresholds
14+
if (vote > 8) return "green";
15+
else if (vote >= 6) return "orange";
1516
else return "red";
1617
};
1718

1819
const showMovies = (movies) => {
1920
main.innerHTML = "";
21+
// Handle No Search Results
22+
if (movies.length === 0) {
23+
main.innerHTML =
24+
'<h1 class="no-results">No movies found. Please try another search.</h1>';
25+
return;
26+
}
2027
movies.forEach((movie) => {
21-
const { title, poster_path, vote_average, overview } = movie;
28+
// Display the Movie's Release Date
29+
const { title, poster_path, vote_average, overview, release_date } = movie;
30+
const year = new Date(release_date).getFullYear();
2231
const movieElement = document.createElement("div");
2332
movieElement.classList.add("movie");
33+
// Handle Missing Movie Posters
34+
// Format Movie Ratings
2435
movieElement.innerHTML = `
25-
<img
26-
src="${IMG_PATH + poster_path}"
27-
alt="${title}"
28-
/>
36+
<img src="${
37+
IMG_PATH + poster_path
38+
}" alt="${title}" onerror="this.src='https://placehold.co/1280x1920/058ED9/FFF?text=${title}&font=poppins'" />
2939
<div class="movie-info">
30-
<h3>${title}</h3>
31-
<span class="${getClassByRate(vote_average)}">${vote_average}</span>
40+
<h3>${title} <span class="release-date">(${year})</span></h3>
41+
<span class="${getClassByRate(vote_average)}">${vote_average.toFixed(
42+
1
43+
)}</span>
3244
</div>
3345
<div class="overview">
3446
<h3>Overview</h3>

017-movie app/style.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ main {
5555
justify-content: center;
5656
}
5757

58+
.no-results {
59+
color: #eee;
60+
text-align: center;
61+
margin: 2rem;
62+
font-size: 1.2rem;
63+
}
64+
5865
.movie {
5966
width: 300px;
6067
margin: 1rem;
@@ -89,6 +96,14 @@ main {
8996
font-weight: bold;
9097
}
9198

99+
/* Display the Movie's Release Date */
100+
.movie-info span.release-date {
101+
background-color: inherit;
102+
padding: 0;
103+
font-size: 0.9rem;
104+
font-weight: lighter;
105+
}
106+
92107
.movie-info span.green {
93108
color: lightgreen;
94109
}

0 commit comments

Comments
 (0)