Skip to content

Instantly share code, notes, and snippets.

@tysonwolker
Last active August 22, 2017 00:45
Show Gist options
  • Save tysonwolker/a10e106d4b8bb11db5a3053405c6ae5c to your computer and use it in GitHub Desktop.
Save tysonwolker/a10e106d4b8bb11db5a3053405c6ae5c to your computer and use it in GitHub Desktop.
Video Store
{
"name": "martin",
"rentals": [
{"movieID": "F001", "days": 3},
{"movieID": "F002", "days": 1},
]
}
{
"F001": {"title": "Ran", "code": "regular"},
"F002": {"title": "Trois Couleurs: Bleu", "code": "regular"}
}
function statement(customer, movies) {
let totalAmount = 0;
let frequentRenterPoints = 0;
let result = `Rental Record for ${customer.name}\n`;
for (let r of customer.rentals) {
let movie = movies[r.movieID];
let thisAmount = 0;
// determine amount for each movie
switch (movie.code) {
case "regular":
thisAmount = 2;
if (r.days > 2) {
thisAmount += (r.days - 2) * 1.5;
}
break;
case "new":
thisAmount = r.days * 3;
break;
case "childrens":
thisAmount = 1.5;
if (r.days > 3) {
thisAmount += (r.days - 3) * 1.5;
}
break;
}
//add frequent renter points
frequentRenterPoints++;
// add bonus for a two day new release rental
if(movie.code === "new" && r.days > 2) frequentRenterPoints++;
//print figures for this rental
result += `\t${movie.title}\t${thisAmount}\n` ;
totalAmount += thisAmount;
}
// add footer lines
result += `Amount owed is ${totalAmount}\n`;
result += `You earned ${frequentRenterPoints} frequent renter points\n`;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment