Untitled
unknown
plain_text
5 months ago
1.4 kB
2
Indexable
function (customer) { var movies = { F001: { title: 'Ran', code: 'regular' }, F002: { title: 'Trois Couleurs: Bleu', code: 'regular' }, F003: { title: 'Cars 2', code: 'childrens' }, F004: { title: 'Latest Hit Release', code: 'new' }, //EXERCISE NOTE: add more movies if you need }; 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; };
Editor is loading...
Leave a Comment