Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function catLife(input) {
- let catBreed = input[0];
- let catGender = input[1];
- let breedYears = 0;
- switch (catBreed) {
- case "British Shorthair":
- breedYears = 13;
- break;
- case "Siamese":
- breedYears = 15;
- break;
- case "Persian":
- breedYears = 14;
- break;
- case "Ragdoll":
- breedYears = 16;
- break;
- case "American Shorthair":
- breedYears = 12;
- break;
- case "Siberian":
- breedYears = 11;
- break;
- default:
- console.log(`${catBreed} is invalid cat!`);
- break;
- }
- if (catGender === "f") {
- breedYears++;
- }
- if (breedYears > 1) {
- console.log(`${breedYears * 2} cat months`);
- }
- }
- Фундаменталс решение:
- function catLife([catBreed, catGender]) {
- let breedYears = {
- "Siberian": 11,
- "American Shorthair": 12,
- "British Shorthair": 13,
- "Persian": 14,
- "Siamese": 15,
- "Ragdoll": 16
- }[catBreed];
- catGender === "f" ? breedYears++ : breedYears;
- console.log(breedYears > 1 ? `${breedYears * 2} cat months` : `${catBreed} is invalid cat!`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement