forked from CodeToExpress/dailycodebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol2.js
More file actions
26 lines (20 loc) · 687 Bytes
/
sol2.js
File metadata and controls
26 lines (20 loc) · 687 Bytes
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
/**
* @author MadhavBahlMD
* @date 20/12/2018
*/
// Step 1: Run a loop from 1 to n, for reach iteration (i) perform the next steps
// Step 2: Declare a temporary empty string (inside loop, say output)
// Step 3: If i is divisible by 3, append Fizz to the output.
// Step 4: If i is divisible by 5, append Buzz to the output.
// Step 5: If output is still an empty string, set it equal to i
// Step 6: Print output.
function fizzbuzz (num) {
for (let i=1; i<=num; i++) {
let opStr = '';
if (i%3 === 0) opStr += 'Fizz';
if (i%5 === 0) opStr += 'Buzz';
if (opStr === '') opStr = i;
console.log (opStr);
}
}
fizzbuzz (17);