diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..59ba0fca 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -6,9 +6,21 @@ */ function evenNumbers(n) { - // TODO + // TODO + // const arr =[]; + // for (let i=0;i<(n*2);i+=2){ + // arr.push(i); + // } + // return arr; + const arr = []; + let i = 0; + while (i < n * 2) { + arr.push(i); + i += 2; + } + return arr; } -evenNumbers(3); // should output 0,2,4 -evenNumbers(0); // should output nothing -evenNumbers(10); // should output 0,2,4,6,8,10,12,14,16,18 +console.log(evenNumbers(3)); // should output 0,2,4 +console.log(evenNumbers(0)); // should output nothing +console.log(evenNumbers(10)); // should output 0,2,4,6,8,10,12,14,16,18 diff --git a/1-exercises/C-while-loop-with-array/exercise.js b/1-exercises/C-while-loop-with-array/exercise.js index d584cd75..a92acade 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -18,6 +18,13 @@ const BIRTHDAYS = [ function findFirstJulyBDay(birthdays) { // TODO + let i=0; + while (i { + return /\d/.test(element); + }); } /* @@ -32,6 +59,12 @@ function headlinesWithNumbers(allArticleTitles) { */ function averageNumberOfCharacters(allArticleTitles) { // TODO + let sum =0; + for ( let i=0 ;i0 ;i--){ + factorial*=i + } + return factorial; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/3-extra/2-array-of-objects.js b/3-extra/2-array-of-objects.js index ee57960f..9dc70160 100644 --- a/3-extra/2-array-of-objects.js +++ b/3-extra/2-array-of-objects.js @@ -12,6 +12,14 @@ function getHighestRatedInEachGenre(books) { // TODO + let arr=[]; + for(let i=0;i { - expect(generateFibonacciSequence(10)).toEqual( - [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] - ); + expect(generateFibonacciSequence(10)).toEqual([ + 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, + ]); }); test("should return the first 5 numbers in the Fibonacci Sequence", () => { - expect(generateFibonacciSequence(5)).toEqual( - [0, 1, 1, 2, 3] - ); + expect(generateFibonacciSequence(5)).toEqual([0, 1, 1, 2, 3]); }); test("should return the first 15 numbers in the Fibonacci Sequence", () => { - expect(generateFibonacciSequence(15)).toEqual( - [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] - ); -}); \ No newline at end of file + expect(generateFibonacciSequence(15)).toEqual([ + 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, + ]); +});