Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function personalTitles(input) {
- let age = Number(input[0]);
- let gender = input[1];
- if (gender == "m") {
- if (age < 16) {
- console.log("Master");
- } else {
- console.log("Mr.");
- }
- } else {
- if (age < 16) {
- console.log("Miss");
- } else {
- console.log("Ms.");
- }
- }
- }
- Решение с тернарен оператор:
- function personalTitles(input) {
- let age = Number(input[0]);
- let gender = input[1];
- console.log(age >= 16? (gender == "f"? "Ms.": "Mr.") : (gender == "f"? "Miss": "Master"));
- }
- Taрикатско решение:)
- function personalTitles(input) {
- console.log(Number(input[0]) >= 16? (input[1] == "f"? "Ms.": "Mr.") : (input[1] == "f"? "Miss": "Master"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement