Blog

Movie rental program with object constructor function:

  function Movie(title, newRelease, year, director, starring, checkedIn, checkedOut){
              this.title = title;
              this.newRelease = newRelease;
              this.year = year;
              this.director = director;
              this.starring = starring;
              this.checkedIn = checkedIn;
              this.checkedOut = checkedOut;

              this.rent = function(numCheckedOut){
                  var moveIn = this.checkedIn - numCheckedOut;
                  var moveOut = this.checkedOut + numCheckedOut;
                  Movie.checkedIn = moveIn;
                  Movie.checkedOut = moveOut;
              };

              this.returnRental = function(numCheckedIn){
                  var moveIn = this.checkedIn + numCheckedIn;
                  var moveOut = this.checkedOut - numCheckedIn;
                  Movie.checkedIn = moveIn;
                  Movie.checkedOut = moveOut;
              };
          }

          var bd_TheHost = new Movie("The Host", false, '2006', 'Bong Joon-ho', 'Song Kang-ho', 2, 0);
          var bd_Speed = new Movie("Speed", false, '1994', 'Jan de Bont', 'Keanu Reeves', 1, 1);

          console.log(bd_TheHost);
          console.log(bd_Speed);

          bd_TheHost.rent(1);
          console.log("Stock Count Update: The Host");
          console.log("Number Checked In: " + Movie.checkedIn);
          console.log("Number Checked Out: " + Movie.checkedOut);
          bd_Speed.returnRental(1);
          console.log("Stock Count Update: Speed");
          console.log("Number Checked In: " + Movie.checkedIn);
          console.log("Number Checked Out: " + Movie.checkedOut);