Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/fizzbuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@ const answer = []

// Write your code below this line

/*
Inside the `src/fizzbuzz.js` file, write a program that populates the `answer` array with numbers from 1 to 15, *except*:

- When the number is a multiple of three (e.g. 3, 6, 9, etc.), the number should be replaced with the word `Fizz`

- When the number is a multiple of five (e.g. 5, 10, etc.), the number should be replaced with the word `Buzz`

- When the number is a multiple of both three *and* five (e.g. 15), the number should be replaced with the word `FizzBuzz`
*/

for (let i = 0; i < 15; i++) {
let insert = ''
let number = i + 1
if (number % 3 === 0) {
insert = insert.concat('Fizz')
if (number % 5 === 0) {
insert = insert.concat('Buzz')
}
answer[i] = insert
continue
}

else if (number % 5 === 0) {
insert = insert.concat('Buzz')
answer[i] = insert
continue
}

else {
answer[i] = number
}

}



Expand Down