Advertisement
teoespero

Arrays, objects and methods

Aug 3rd, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.  
  3.                 var movies = [
  4.                     {
  5.                         title: "Red Sparrow",
  6.                         hasWatched: true,
  7.                         rating: 6.6
  8.                     },                         
  9.                     {
  10.                         title: "Wonder",
  11.                         hasWatched: true,
  12.                         rating: 8
  13.                     },
  14.                     {
  15.                         title: "Wedding Crashers",
  16.                         hasWatched: false,
  17.                         rating: 7.0
  18.                     },
  19.                     {
  20.                         title: "The Internship",                               
  21.                         hasWatched: true,
  22.                         rating: 6.3
  23.                     },
  24.                     {
  25.                         title: "Starsky & Hutch",
  26.                         hasWatched: true,
  27.                         rating: 6.1
  28.                     },
  29.                     {
  30.                         title: "Meet the Fockers",
  31.                         hasWatched: true,
  32.                         rating: 6.3
  33.                     }
  34.                 ]
  35.                 rater.prototype.percentage = function(movieRating, scale){
  36.                         return (movieRating/scale) * 100;
  37.                     }
  38.                
  39.  
  40.                 var movieTitle = "";
  41.                 var theRating = 0.0;
  42.  
  43.  
  44.                 for (counter = 0; counter < Object.keys(movies).length; counter++){
  45.                     movieTitle = movies[counter].title;
  46.                     theRating = (movies.percentage(movies[counter].rating,10));
  47.                     document.write("<p>");
  48.                     document.write("<b>Movie title: </b>" + movieTitle + "<br>");
  49.                     document.write("<b>IMDB Rating: </b>" + theRating.toFixed(2) + "<br>");
  50.                     document.write("</p>");
  51.             }
  52.             </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement