Blog

Movie rental program with object literal notation:

		var movieRental = {
			title: 'Toy Story',
			newRelease: false,
			checkedIn: 3,
			checkedOut: 0,
			rent: function(numCheckedOut){
				var moveIn = this.checkedIn - numCheckedOut;
				var moveOut = this.checkedOut + numCheckedOut;
				movieRental.checkedIn = moveIn;
				movieRental.checkedOut = moveOut;
			},
			returnRental: function (numCheckedIn){
				var moveIn = this.checkedIn + numCheckedIn;
				var moveOut = this.checkedOut - numCheckedIn;
				movieRental.checkedIn = moveIn;
				movieRental.checkedOut = moveOut;
			}
		}

		movieRental.rent(1);
		console.log("Stock Count Update: Toy Story");
		console.log("Number Checked In: " + movieRental.checkedIn);
		console.log("Number Checked Out: " + movieRental.checkedOut);

		movieRental.returnRental(1);
		console.log("Stock Count Update: Toy Story");
		console.log("Number Checked In: " + movieRental.checkedIn);
		console.log("Number Checked Out: " + movieRental.checkedOut);