Advertisement
Spocoman

08.Cinema Ticket

Dec 19th, 2021 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinemaTicket(input) {
  2.     let dayOfWeek = input[0];
  3.     let price = 0;
  4.  
  5.     if (dayOfWeek === "Monday" || dayOfWeek === "Tuesday" || dayOfWeek === "Friday") {
  6.         price = 12;
  7.     } else if (dayOfWeek === "Wednesday" || dayOfWeek === "Thursday") {
  8.         price = 14;
  9.     } else {
  10.         price = 16;
  11.     }
  12.     console.log(price);
  13. }
  14.  
  15. Решение със switch:
  16.  
  17. function cinemaTicket(input){
  18.     let day = input[0];
  19.     let price = 0;
  20.  
  21.     switch (day){
  22.         case "Monday":
  23.         case "Tuesday":
  24.         case "Friday":
  25.             price = 12;
  26.             break;
  27.         case "Wednesday":
  28.         case "Thursday":
  29.             price = 14;
  30.             break;
  31.         case "Saturday":
  32.         case "Sunday":
  33.             price = 16;
  34.             break;
  35.     }
  36.     console.log(price);
  37. }
  38.  
  39. Pешение с тернарен оператор:)
  40.  
  41. function cinemaTicket(day) {
  42.     console.log(day[0] == "Saturday" || day[0] == "Sunday"? 16 : day[0] == "Wednesday" || day[0] == "Thursday"? 14 : 12);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement