×
countdown
countdown
that accepts a number as a parameter and every 1000 milliseconds decrements the value and console.logs it. Once the value is 0 it should log "DONE!" and stop. countDown(4); // 3 // 2 // 1 // "DONE!"
randomGame
randomGame
that selects a random number between 0 and 1 every 1000 milliseconds and each time that a random number is picked, add 1 to a counter. If the number is greater than .75
, stop the timer and return the number of tries it took before we found a number greater than .75
.isEven
isEven
which takes in a number and returns true if the number is even and returns false if it is notisEven(2); // true isEven(3); // false
isOdd
isOdd
which takes in a number and returns true if the number is odd and returns false if it is notisOdd(3); // true isOdd(14); // false
isPrime
isPrime
which takes in a number and returns true if the number is a prime number (is greater than 1 and can only be divided in whole by itself and 1), otherwise returns falseisPrime(8); // false isPrime(17); // true
numberFact
numberFact
which takes in a number and a callback and returns the result of the callback with the number passed to itnumberFact(59,isEven); // false numberFact(59,isOdd); // true numberFact(59,isPrime); // true
find
find
. It should take in an array and a callback and return the first value found in the array that matches the condition. find([8,11,4,27], function(val){return val >= 10}); // 11 find([8,11,4,27], function(val){return val === 5}); // undefined
findIndex
findIndex
. It should take in an array and a callback and return the index of first value found in the array that matches the condition. // returns 1 (index of the first value greater than or equal to 10) findIndex([8,11,4,27], function(val){return val >= 10}); findIndex([8,11,4,27], function(val){return val === 7}); // undefined
specialMultiply
specialMultiply
which accepts two parameters. If the function is passed both parameters, it should return the product of the two. If the function is only passed one parameter - it should return a function which can later be passed another parameter to return the product. You will have to use closure and arguments to solve this.specialMultiply(3,4); // 12 specialMultiply(3)(4); // 12 specialMultiply(3); // returns a function
You can find solutions to the exercises here
When you're ready, move on to Introduction to the DOM