|
1 | 1 | // Do not change any of the function names |
2 | 2 |
|
3 | 3 | const getBiggest = (x, y) => { |
4 | | - if (x > y){ |
| 4 | + if (x > y) { |
5 | 5 | return x; |
6 | | - } else { |
7 | | - return y; |
8 | 6 | } |
| 7 | + return y; |
9 | 8 |
|
10 | 9 | // x and y are integers. Return the larger integer |
11 | 10 | // if they are the same return either one |
12 | 11 | }; |
13 | 12 |
|
14 | 13 | const greeting = (language) => { |
| 14 | + const translations = { |
| 15 | + German: 'Guten Tag!', |
| 16 | + Spanish: 'Hola!', |
| 17 | + Chinese: 'Ni Hao!', |
| 18 | + }; |
| 19 | + return translations[language] || 'Hello!'; |
15 | 20 | // return a greeting for three different languages: |
16 | 21 | // language: 'German' -> 'Guten Tag!' |
17 | 22 | // language: 'Spanish' -> 'Hola!' |
18 | 23 | // language: 'Chinese' -> 'Ni Hao!' |
19 | 24 | // if language is undefined return 'Hello!' |
20 | 25 | }; |
21 | 26 |
|
22 | | -const isTenOrFive = (num) => { |
| 27 | +const isTenOrFive = num => num === 10 || num === 5; |
23 | 28 | // return true if num is 10 or 5 |
24 | 29 | // otherwise return false |
25 | | -}; |
26 | 30 |
|
27 | | -const isInRange = (num) => { |
| 31 | + |
| 32 | +const isInRange = num => num < 50 && num > 20; |
28 | 33 | // return true if num is less than 50 and greater than 20 |
29 | | -}; |
30 | 34 |
|
31 | | -const isInteger = (num) => { |
| 35 | +const isInteger = num => Math.floor(num) === num; |
32 | 36 | // return true if num is an integer |
33 | 37 | // 0.8 -> false |
34 | 38 | // 1 -> true |
35 | 39 | // -10 -> true |
36 | 40 | // otherwise return false |
37 | 41 | // hint: you can solve this using Math.floor |
38 | | -}; |
39 | 42 |
|
40 | 43 | const fizzBuzz = (num) => { |
| 44 | + if (num % 3 === 0 && num % 5 === 0) { |
| 45 | + return 'fizzbuzz'; |
| 46 | + } |
| 47 | + else if (num % 3 === 0) { |
| 48 | + return 'fizz'; |
| 49 | + } |
| 50 | + else if (num % 5 === 0) { |
| 51 | + return 'buzz'; |
| 52 | + } |
| 53 | + return num; |
41 | 54 | // if num is divisible by 3 return 'fizz' |
42 | 55 | // if num is divisible by 5 return 'buzz' |
43 | 56 | // if num is divisible by 3 & 5 return 'fizzbuzz' |
44 | 57 | // otherwise return num |
45 | 58 | }; |
46 | 59 |
|
47 | 60 | const isPrime = (num) => { |
| 61 | + if (num < 2) { |
| 62 | + return false; |
| 63 | + } |
| 64 | + if (num % 2 === 0 && num !== 2) { |
| 65 | + return false; |
| 66 | + } |
| 67 | + for (let i = 3; i < Math.floor(num / 2); i++) { |
| 68 | + if (num % i === 0) { |
| 69 | + return false; |
| 70 | + } |
| 71 | + } |
| 72 | + return true; |
48 | 73 | // return true if num is prime. |
49 | 74 | // otherwise return false |
50 | 75 | // hint: a prime number is only evenly divisible by itself and 1 |
|
0 commit comments