diff --git a/01-smacss-media-queries/challenges/challenges-01.test.js b/01-smacss-media-queries/challenges/challenges-01.test.js index f9ca403..bdc16f6 100644 --- a/01-smacss-media-queries/challenges/challenges-01.test.js +++ b/01-smacss-media-queries/challenges/challenges-01.test.js @@ -9,11 +9,11 @@ Then, write a function named speaker that takes in a string and a callback funct ------------------------------------------------------------------------------------------------ */ const greeting = (word) => { - // Solution code here... + return word.toUpperCase(); } const speaker = (message, callback) => { - // Solution code here... + return callback(message); } /* ------------------------------------------------------------------------------------------------ @@ -33,11 +33,14 @@ Return the modified array. ------------------------------------------------------------------------------------------------ */ const addValues = (arr, value) => { - // Solution code here... + arr.push(value); } const addNumbers = (num, arr, times, callback) => { - // Solution code here... + for(let i = 0; i < times; i++){ + arr.push(num); + } + return arr; } /* ------------------------------------------------------------------------------------------------ @@ -53,11 +56,16 @@ Return the modified array. ------------------------------------------------------------------------------------------------ */ const removeOne = (num, arr) => { - // Solution code here... + if(num % 3 === 2){ + arr.pop(); + } } const removeElements = (arr, callback) => { - // Solution code here... + for (let i = 0; i < arr.length; i++){ + callback(arr[i], arr); + } + return arr; } /* ------------------------------------------------------------------------------------------------ @@ -67,7 +75,10 @@ Write a function named removeWithForEach that produces the same output as challe ------------------------------------------------------------------------------------------------ */ const removeWithForEach = (arr, callback) => { - // Solution code here... + arr.forEach((val) => { + callback(val, arr) + }) + return arr; } /* ------------------------------------------------------------------------------------------------ @@ -81,7 +92,12 @@ This anonymous function should accept up to three arguments: the element, the in ------------------------------------------------------------------------------------------------ */ const removeWithAnon = (arr) => { - // Solution code here... + arr.forEach((val, index, arr) => { + if(val % 3 === 2){ + arr.pop(); + } + }) + return arr; } /* ------------------------------------------------------------------------------------------------ @@ -102,7 +118,13 @@ This function should use forEach to populate your grocery list based on the stor ------------------------------------------------------------------------------------------------ */ const createList = (availableItems) => { - // Solution code here... + let groceryList = []; + availableItems.forEach((val) => { + if (val.available === true) { + groceryList.push(val.name); + } + }) + return groceryList; } /* ------------------------------------------------------------------------------------------------ @@ -120,7 +142,22 @@ Return the resulting output array. ------------------------------------------------------------------------------------------------ */ const fizzbuzz = (arr) => { - // Solution code here... + let output = []; + arr.forEach((val) => { + if ((val % 3 === 0) && (val % 5 === 0)) { + output.push("Fizz Buzz") + } + else if (val % 3 === 0){ + output.push("Fizz"); + } + else if (val % 5 === 0){ + output.push("Buzz"); + } + else { + output.push(val); + } + }) + return output; } /* ------------------------------------------------------------------------------------------------