-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboomIntensity.js
39 lines (35 loc) · 1.59 KB
/
boomIntensity.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Given a number, return a string of the word "Boom", which varies in the following ways:
// The string should include n number of "o"s, unless n is below 2 (in that case, return "boom").
// If n is evenly divisible by 2, add an exclamation mark to the end.
// If n is evenly divisible by 5, return the string in ALL CAPS.
// If n is evenly divisible by both 2 and 5, return the string in ALL CAPS and add an exclamation mark to the end.
// The example below should help clarify these instructions.
// Examples:
// boomIntensity(4) ➞ "Boooom!"
// // There are 4 "o"s and 4 is divisible by 2 (exclamation mark included)
// boomIntensity(1) ➞ "boom"
// // 1 is lower than 2, so we return "boom"
// boomIntensity(5) ➞ "BOOOOOM"
// // There are 5 "o"s and 5 is divisible by 5 (all caps)
// boomIntensity(10) ➞ "BOOOOOOOOOOM!"
// // There are 10 "o"s and 10 is divisible by 2 and 5 (all caps and exclamation mark included)
// Notes:
// A number which is evenly divisible by 2 and 5 will have both effects applied (see example #4).
// "Boom" will always start with a capital "B", except when n is less than 2, then return a minature explosion as "boom".
function boomIntensity(n) {
let test = "o";
if (n === 0) {
return "boom";
} else if (n % 2 === 0 && n % 5 === 0) {
return "B" + test.toUpperCase().repeat(n) + "M" + "!";
} else if (n < 2) {
return "boom";
} else if (n % 2 === 0) {
return "B" + test.repeat(n) + "m" + "!";
} else if (n % 5 === 0) {
return "B" + test.toUpperCase().repeat(n) + "M";
} else {
return "B" + test.repeat(n) + "m";
}
}
console.log(boomIntensity(0));