I have been trying to out only the rating and title of the movie but when consolelog highestRated I keep on getting the full object. How do I console.log only the highestRated rating and the Movie-title of highestRated rating
sample output;
highest rated : Joker (10)
let movies = [
{
movieTitle: `Fast & Furious Presents`,
releaseYear: 2019,
rating: 6.4,
genre: [`Action`, `Adventure`, `Thriller`],
format: `digital`
},
{
movieTitle: `Joker`,
releaseYear: 2019,
rating: 10,
genre: [`Crime`, `Drama`, `Thriller`],
format: `digital`
},
{
movieTitle: `The Fast Saga`,
releaseYear: 2021 ,
rating: 5.2,
genre: [`Action`, `Adventure`, `Crime`]
},
{
movieTitle: `Avengers Infinity War`,
releaseYear: 2018,
rating: 8.4,
genre: [`Action`, `Adventure`, `Sci-Fi`]
},
{
movieTitle: `Darkest Hour`,
releaseYear: 2017,
rating: 7.4,
genre: [`Drama`, `Biography`, `History`]
},
{
movieTitle: `Mortal Kombat `,
releaseYear: 2021,
rating: 6.2,
genre: [`Action`, `Fantasy`, `Adventure`, `Thriller`],
format: `digital`
}
];
movies.forEach(movie => {
if (movie.format !== `Digital`) movie.format = `Film`;
} );
movies.sort((a,b) =>b.rating - a.rating);
;
let movieTitles = movies.map(movie => {
return movie.movieTitle;
})
let highestRated = movies.reduce ( (high, movies) => high.rating > movies.rating ? high : movies);
let lowestRated = movies.reduce ( (low, movies) => low.rating < movies.rating ? low : movies);
let highlyRated = movies.filter(m => m.rating >= 7);
let highlyRatedTitles = highlyRated.map(function (m) {
return m.movieTitle;
});
console.log(Movie titles = ${movieTitles} .
);
console.log(Highest rated Movies = ${highlyRatedTitles} .
);
CodePudding user response:
To get highestRated rating and highestRated movieTitle
// movieTitle
console.log(highestRated.movieTitle);
// rating
console.log(highestRated.rating);
// Output highest rated: Joker(10)
console.log(`highest rated : ${highestRated.movieTitle} (${highestRated.rating})`);