Advertisement
Spocoman

07.Working Hours

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