Challenges
Write a
multiply
function that finds the product of two numbers.multiply(5, 7) => 35
Write a function that takes in a number and returns
true
if the number is even andfalse
if the number is odd (Hint: Look up the%
operator).isEven(4) => true
Write a function that swaps two values at two different indexes in an array.
swap(["moe", "larry", "curly"], 0, 2) => ["curly", "larry", "moe"]
Write a function that generates a random number in a specified range (Hint: Look up Math.random()).
getRand(5, 10) => 8 (any number between 5 and 10)
Write a function that generates an array of specified length that contains random numbers from 1 to 100.
randArr(3) => [23, 11, 82]
Stretch Challenges
Write a
getMax
function that finds the maximum number in an array.Write a function called
explainMather
that takes in three arguments: two numbers and a function calledmather
. TheexplainMather
function should pass the two numbers intomather
and write out a message in the console to show the two number inputs and the output frommather
. TestexplainMather
by passing in yourmultiply
function from challenge #1.Write a
vowels
function that counts the number of vowels in a given string.merge(arr1, arr2)
Write a function that takes two sorted arrays of numbers and returns a merged array of the sorted numbers. For example, if the input arrays were
var arr1 = [3,6,11]
andvar arr2 = [2,4,5,8,9]
, the returned array would be:[2,3,4,5,6,8,9,11]
.letterCount(word)
Write a function that counts the number of times each letter occurs in a given string. It should return an object containing the count for each letter. For example, the string "apple" would return the following:
{ a: 1, p: 2, l: 1, e: 1 }
Bonus: Make sure that lower case letters and upper case letters count for the same character. Also, ignore spaces and punctuation.
sillySum(arr)
Write a function that takes an array of numbers and returns the sum of each number multiplied by its index.
count += (number * index)
numSquare(max)
Create a function called
numSquare
that will return an array of all perfect square numbers up to, but not exceeding a max number.