Advertisement
Spocoman

02. Summer Outfit

Dec 20th, 2021 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function summerOutfit(input) {
  2.     let gradus = Number(input[0]);
  3.     let time = input[1];
  4.     let outfit = "Shirt";
  5.     let shoes = "Moccasins";
  6.  
  7.     if (time === "Morning") {
  8.         if (gradus >= 10 && gradus <= 18) {
  9.             outfit = "Sweatshirt";
  10.             shoes = "Sneakers";
  11.         } else if (gradus > 24) {
  12.             outfit = "T-Shirt";
  13.             shoes = "Sandals";
  14.         }
  15.     } else if (time === "Afternoon") {
  16.         if (gradus > 18 && gradus <= 24) {
  17.             outfit = "T-Shirt";
  18.             shoes = "Sandals";
  19.         } else if (gradus > 24) {
  20.             outfit = "Swim Suit";
  21.             shoes = "Barefoot";
  22.         }
  23.     }
  24.     console.log(`It\'s ${gradus} degrees, get your ${outfit} and ${shoes}.`);
  25. }
  26.  
  27. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  28.  
  29. function summerOutfit(input) {
  30.    let gradus = Number(input[0]);
  31.    let time = input[1];
  32.  
  33.    let outfit = time === "Morning" ? (gradus >= 10 && gradus <= 18 ? "Sweatshirt" : gradus > 24 ? "T-Shirt" : "Shirt") :
  34.        time === `Afternoon` ? (gradus > 18 && gradus <= 24 ? "T-Shirt" : gradus > 24 ? "Swim Suit" : "Shirt") : "Shirt";
  35.  
  36.    let shoes = time === "Morning" ? (gradus >= 10 && gradus <= 18 ? "Sneakers" : gradus > 24 ? "Sandals" : "Moccasins") :
  37.        time === "Afternoon" ? (gradus > 18 && gradus <= 24 ? "Sandals" : gradus > 24 ? "Barefoot" : "Moccasins") : "Moccasins";
  38.  
  39.    console.log(`It\'s ${gradus} degrees, get your ${outfit} and ${shoes}.`);
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement