Skip to content

Commit c0e50d2

Browse files
committed
up to isPrime
1 parent 3de5596 commit c0e50d2

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

src/project-2.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,75 @@
11
// Do not change any of the function names
22

33
const getBiggest = (x, y) => {
4-
if (x > y){
4+
if (x > y) {
55
return x;
6-
} else {
7-
return y;
86
}
7+
return y;
98

109
// x and y are integers. Return the larger integer
1110
// if they are the same return either one
1211
};
1312

1413
const greeting = (language) => {
14+
const translations = {
15+
German: 'Guten Tag!',
16+
Spanish: 'Hola!',
17+
Chinese: 'Ni Hao!',
18+
};
19+
return translations[language] || 'Hello!';
1520
// return a greeting for three different languages:
1621
// language: 'German' -> 'Guten Tag!'
1722
// language: 'Spanish' -> 'Hola!'
1823
// language: 'Chinese' -> 'Ni Hao!'
1924
// if language is undefined return 'Hello!'
2025
};
2126

22-
const isTenOrFive = (num) => {
27+
const isTenOrFive = num => num === 10 || num === 5;
2328
// return true if num is 10 or 5
2429
// otherwise return false
25-
};
2630

27-
const isInRange = (num) => {
31+
32+
const isInRange = num => num < 50 && num > 20;
2833
// return true if num is less than 50 and greater than 20
29-
};
3034

31-
const isInteger = (num) => {
35+
const isInteger = num => Math.floor(num) === num;
3236
// return true if num is an integer
3337
// 0.8 -> false
3438
// 1 -> true
3539
// -10 -> true
3640
// otherwise return false
3741
// hint: you can solve this using Math.floor
38-
};
3942

4043
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;
4154
// if num is divisible by 3 return 'fizz'
4255
// if num is divisible by 5 return 'buzz'
4356
// if num is divisible by 3 & 5 return 'fizzbuzz'
4457
// otherwise return num
4558
};
4659

4760
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;
4873
// return true if num is prime.
4974
// otherwise return false
5075
// hint: a prime number is only evenly divisible by itself and 1

0 commit comments

Comments
 (0)