- Create two functions:
double
andsquare
.double
should take a number and return the number times two.
function double(num){ return (num * 2) }
square
should take a number and return the number squared.
const square = (num) => { return (num * num) }
- Create a third function
doubleSquare
that uses both of the functions to return a number that is first doubled and then squared.
function doubleSquare(num) { return square(double(num)) }
- Create a function
classyGreeting
that takes as input the stringsfirstName
andlastName
, and returns a string with a greeting using the two.
function classyGreeting(firstName, lastName) { return ("hello there " + firstName + lastName) }
- Create a second function
yell
that takes string as input and returns the string in all capitalized letters. - Create a third function
yellGreeting
that will take thefirstName
andlastName
as inputs and yell a greeting using the two.
- The concat array method is used to merge two (or more) arrays.
Write a
removeDupes
function that takes an array as an argument and returns a copy without any duplicate elements. Then, write a functionconcatAndRemoveDupes
that combines two arrays and removes any duplicates.
Hint: Use the array method includes
, an object, or a Set. Or the spread operator instead of concat.
- Given a list of grades, we can get the median grade by sorting the list and taking the middle element, or the average of the two middle elements.
Create the functions
sort
andmiddleElement
, and then use them to create the functionsmedian
.
let grades = [91, 85, 100, 92, 88];
console.log(median(grades)); // Should log 91
-
Write a function called
repeat
that takes in a string and numberOfTimes. The function should log to the screen the string however many times as numberOfTimes. If the user does not enter a numberOfTimes it should default to 2. -
Using the spread operator, write a function that can take any number of arguments and return the sum of all of them.
-
Write a function called
adder
takes in one number and returns a function that will add that number with another number. Usingadder
create anadd5
and anadd9
function. Hint: Closures!