Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cinemaTicket(input) {
- let dayOfWeek = input[0];
- let price = 0;
- if (dayOfWeek === "Monday" || dayOfWeek === "Tuesday" || dayOfWeek === "Friday") {
- price = 12;
- } else if (dayOfWeek === "Wednesday" || dayOfWeek === "Thursday") {
- price = 14;
- } else {
- price = 16;
- }
- console.log(price);
- }
- Решение със switch:
- function cinemaTicket(input){
- let day = input[0];
- let price = 0;
- switch (day){
- case "Monday":
- case "Tuesday":
- case "Friday":
- price = 12;
- break;
- case "Wednesday":
- case "Thursday":
- price = 14;
- break;
- case "Saturday":
- case "Sunday":
- price = 16;
- break;
- }
- console.log(price);
- }
- Pешение с тернарен оператор:)
- function cinemaTicket(day) {
- console.log(day[0] == "Saturday" || day[0] == "Sunday"? 16 : day[0] == "Wednesday" || day[0] == "Thursday"? 14 : 12);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement