Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function filmPremiere(input) {
- let movie = input.shift();
- let moviePack = input.shift();
- let tickets = Number(input.shift());
- let ticketPrice = 0;
- switch (movie) {
- case "John Wick":
- switch (moviePack) {
- case "Drink":
- ticketPrice = 12;
- break;
- case "Popcorn":
- ticketPrice = 15;
- break;
- case "Menu":
- ticketPrice = 19;
- break;
- }
- break;
- case "Star Wars":
- switch (moviePack) {
- case "Drink":
- ticketPrice = 18;
- break;
- case "Popcorn":
- ticketPrice = 25;
- break;
- case "Menu":
- ticketPrice = 30;
- break;
- }
- break;
- case "Jumanji":
- switch (moviePack) {
- case "Drink":
- ticketPrice = 9;
- break;
- case "Popcorn":
- ticketPrice = 11;
- break;
- case "Menu":
- ticketPrice = 14;
- break;
- }
- break;
- }
- if (movie === "Star Wars" && tickets >= 4) {
- ticketPrice *= 0.7;
- } else if (movie === "Jumanji" && tickets === 2) {
- ticketPrice *= 0.85;
- }
- console.log(`Your bill is ${(ticketPrice * tickets).toFixed(2)} leva.`);
- }
- Решение с тернарен оператор:
- function filmPremiere(input) {
- let movie = input.shift();
- let moviePack = input.shift();
- let tickets = Number(input.shift());
- let ticketPrice =
- movie === "John Wick" ? (moviePack === "Drink" ? 12 : moviePack === "Popcorn" ? 15 : 19) :
- movie === "Star Wars" ? (moviePack === "Drink" ? 18 : moviePack === "Popcorn" ? 25 : 30) :
- movie === "Jumanji" ? (moviePack === "Drink" ? 9 : moviePack === "Popcorn" ? 11 : 14) : 0;
- ticketPrice *=
- movie === "Star Wars" && tickets >= 4 ? 0.70 : movie === "Jumanji" && tickets === 2 ? 0.85 : 1;
- console.log(`Your bill is ${(ticketPrice * tickets).toFixed(2)} leva.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement