Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function movieRating(input) {
- let index = 0;
- let moviesNum = Number(input[index]);
- index++;
- let topMovie;
- let worstMovie;
- let lowestScore = 0;
- let highestScore = 0;
- let sumRating = 0;
- for (i = 0; i < moviesNum; i++) {
- let currentMovie = input[index];
- index++;
- let currentScore = Number(input[index]);
- index++;
- sumRating += currentScore;
- if (currentScore > highestScore) {
- currentScore = highestScore;
- topMovie = currentMovie;
- }
- lowestScore = currentScore;
- worstMovie = currentMovie;
- if (currentScore < lowestScore) {
- lowestScore = currentScore;
- }
- }
- console.log(`${topMovie} is with highest rating: ${highestScore}`);
- console.log(`${worstMovie} is with lowest rating: ${lowestScore}`);
- console.log(`Average rating: ${(sumRating / moviesNum).toFixed(1)}`);
- }
- movieRating(["5", "A Star is Born", "7.8", "Creed 2", "7.3", "Mary Poppins", "7.2", "Vice", "7.2", "Captain Marvel", "7.1"]);
- movieRating(["3", "Interstellar", "8.5", "Dangal", "8.3", "Green Book", "8.2"]);
Add Comment
Please, Sign In to add comment