-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathfizzBuzz.js
More file actions
21 lines (20 loc) · 786 Bytes
/
fizzBuzz.js
File metadata and controls
21 lines (20 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Given a positive integer A, return an array of strings with all the integers from 1 to N. But for multiples of 3 the array should have “Fizz” instead of the number. For the multiples of 5, the array should have “Buzz” instead of the number. For numbers which are multiple of 3 and 5 both, the array should have "FizzBuzz" instead of the number.
function fizzBuzz(A){
let out = [];
for(let num = 1; num <= A; num++){
let remainderBy5 = num % 5;
let remainderBy3 = num % 3;
if((!remainderBy5) && (!remainderBy3) ){
out.push( "FizzBuzz");
}else if(!remainderBy3){
out.push( "Fizz");
}else if(!remainderBy5){
out.push( "Buzz");
}else{
out.push(num);
}
}
return out;
}
let A = 5;
console.log(fizzBuzz(A));