Advertisement
Spocoman

04. Personal Titles

Dec 19th, 2021 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function personalTitles(input) {
  2.     let age = Number(input[0]);
  3.     let gender = input[1];
  4.  
  5.     if (gender == "m") {
  6.         if (age < 16) {
  7.             console.log("Master");
  8.         } else {
  9.             console.log("Mr.");
  10.         }
  11.     } else {
  12.         if (age < 16) {
  13.             console.log("Miss");
  14.         } else {
  15.             console.log("Ms.");
  16.         }
  17.     }
  18. }
  19.  
  20. Решение с тернарен оператор:
  21.  
  22. function personalTitles(input) {
  23.     let age = Number(input[0]);
  24.     let gender = input[1];
  25.  
  26.     console.log(age >= 16? (gender == "f"? "Ms.": "Mr.") : (gender == "f"? "Miss": "Master"));    
  27. }
  28.  
  29. Taрикатско решение:)
  30.  
  31. function personalTitles(input) {
  32.    
  33.     console.log(Number(input[0]) >= 16? (input[1] == "f"? "Ms.": "Mr.") : (input[1] == "f"? "Miss": "Master"));    
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement