From 3e0219b1866d2cfe1339a249e726ed3fc4272d5e Mon Sep 17 00:00:00 2001 From: Son Nguyen Date: Sun, 7 Jan 2024 00:02:30 +0700 Subject: [PATCH] Fixed movie rating bugs --- src/js/movie-details.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/js/movie-details.js b/src/js/movie-details.js index 76842928..329b685d 100644 --- a/src/js/movie-details.js +++ b/src/js/movie-details.js @@ -812,23 +812,21 @@ function populateMovieDetails(movie, imdbRating, rtRating, metascore, awards, ra movieDescription.appendChild(keywordsElement); updateFavoriteButton(movie.id); favoriteButton.addEventListener('click', () => toggleFavorite(movie)); - - if (ratedElement.includes('Restricted')) { - document.getElementById('movie-rated-element').title = 'This movie is rated R (Restricted). It contains adult content and it is not recommended for children under 17.'; - } - else if (ratedElement.includes('Strongly Cautioned')) { - document.getElementById('movie-rated-element').title = 'This movie is rated PG-13 (Parents Strongly Cautioned). Some material may be inappropriate for children under 13.'; - } - else if (ratedElement.includes('Parental Guidance')) { - document.getElementById('movie-rated-element').title = 'This movie is rated PG (Parental Guidance Suggested). Some material may not be suitable for children.'; - } - else if (ratedElement.includes('General')) { - document.getElementById('movie-rated-element').title = 'This movie is rated G (General Audiences). All ages admitted.'; - } - else { - document.getElementById('movie-rated-element').title = 'Rating information unavailable.'; - } applySettings(); + const movieRatedElement = document.getElementById('movie-rated-element'); + if (movieRatedElement) { + if (ratedElement.includes('Restricted')) { + movieRatedElement.title = 'This movie is rated R (Restricted). It contains adult content and it is not recommended for children under 17.'; + } else if (ratedElement.includes('Strongly Cautioned')) { + movieRatedElement.title = 'This movie is rated PG-13 (Parents Strongly Cautioned). Some material may be inappropriate for children under 13.'; + } else if (ratedElement.includes('Parental Guidance')) { + movieRatedElement.title = 'This movie is rated PG (Parental Guidance Suggested). Some material may not be suitable for children.'; + } else if (ratedElement.includes('General')) { + movieRatedElement.title = 'This movie is rated G (General Audiences). All ages admitted.'; + } else { + movieRatedElement.title = 'Rating information unavailable.'; + } + } } function getSavedTextColor() {