@@ -3,6 +3,8 @@ if (typeof define !== 'function') { var define = require('amdefine')(module); }
3
3
define ( function ( ) {
4
4
return {
5
5
fizzBuzz : function ( num ) {
6
+
7
+ // INSTRUCTIONS
6
8
// write a function that receives a number as its argument;
7
9
// if the number is divisible by 3, the function should return 'fizz';
8
10
// if the number is divisible by 5, the function should return 'buzz';
@@ -11,25 +13,35 @@ define(function() {
11
13
//
12
14
// otherwise the function should return the number, or false if no number
13
15
// was provided or if the value provided was not a number
14
- if ( typeof num !== 'number' ) { return false ; }
15
16
16
- // not divisible by 3 or 5
17
- if ( num % 3 && num % 5 ) {
18
- return num ;
17
+ // make sure the value provided was a number, if not, return false
18
+ if ( typeof num !== 'number' ) {
19
+ return false ;
19
20
}
20
21
21
- // divisible by 3 but not 5
22
- if ( num % 5 ) {
22
+ // if the number is divisible by 3 AND 5, then when divided by both,
23
+ // the remainder for each operation will be zero
24
+ // return 'fizzbuzz'
25
+ if ( num % 3 === 0 && num % 5 === 0 ) {
26
+ return 'fizzbuzz' ;
27
+ }
28
+
29
+ // if the number is divisible by 3, when divided by 3, the remainder is zero
30
+ // return 'fizz'
31
+ if ( num % 3 === 0 ) {
23
32
return 'fizz' ;
24
33
}
25
34
26
- // divisible by 5 but not 3
27
- if ( num % 3 ) {
35
+ // if the number is divisible by 5, when divided by 5, the remainder is zero
36
+ // return 'buzz'
37
+ if ( num % 5 === 0 ) {
28
38
return 'buzz' ;
29
39
}
30
40
31
- // divisible by 5 and 3
32
- return 'fizzbuzz' ;
41
+ // if the number is not divisble by 3 or 5, i.e. has skipped all previous
42
+ // conditions, return the number
43
+ return num ;
44
+
33
45
}
34
46
} ;
35
47
} ) ;
0 commit comments