1+ 'use strict' ;
2+
3+ // Don't you just love the thrill of the lottery? What if I told you we can
4+ // make our own lottery machine? Let's get started!
5+ // Write a function that takes 4 arguments.
6+ // A start value
7+ // An end value
8+ // A callback that executes if the number is divisible by 3
9+ // A callback that executes if the number is divisible by 5
10+ // The function should first generate an array containing values from start
11+ // value to end value (inclusive).
12+ // Then the function should take the newly created array and iterate over it,
13+ // and calling the first callback if the array value is divisible by 3.
14+ // The function should call the second callback if the array value is
15+ // divisible by 5.
16+ // Both functions should be called if the array value is divisible by both 3
17+ // and 5.
18+ // Here is a starter template:
19+
20+ function threeFive ( startIndex , stopIndex , threeCallback , fiveCallback ) {
21+ const numbers = [ ] ;
22+ // make array
23+ // start at beginning of array and check if you should call threeCallback
24+ // or fiveCallback or go on to next
25+ }
26+
27+ threeFive ( 10 , 15 , sayThree , sayFive ) ;
28+ // Should create an array [10,11,12,13,14,15]
29+ // and call sayFive, sayThree, sayThree, sayFive
30+
31+ ////////////////////////////////////
32+
33+ function threeFive ( startIndex , stopIndex , threeCallback , fiveCallback ) {
34+ const numbers = [ ] ;
35+
36+ for ( let i = startIndex ; i <= stopIndex ; i ++ ) {
37+ numbers . push ( i ) ;
38+ }
39+
40+ console . log ( numbers ) ;
41+
42+ for ( const number of numbers ) {
43+ threeCallback ( number ) ;
44+ fiveCallback ( number ) ;
45+ }
46+ }
47+
48+ const sayThree = number => {
49+ if ( number % 3 === 0 ) {
50+ return console . log ( "The number" + number + "can be divisible with 3" ) ;
51+ }
52+ } ;
53+
54+ const sayFive = number => {
55+ if ( number % 5 === 0 ) {
56+ return console . log ( `The number ${ number } can be divisible with 5` ) ;
57+ }
58+ } ;
59+
60+ threeFive ( 10 , 15 , sayThree , sayFive ) ;
61+ threeFive ( 17 , 33 , sayThree , sayFive ) ;
0 commit comments