- Create a function called
repeat
which takes two arguments:- The first argument should be an arbitrary function,
fn
- The second argument should be a number,
n
- The first argument should be an arbitrary function,
repeat
should loopn
times- Each iteration of the loop, it should call
fn
- Create two more functions called
hello
andgoodbye
:hello
should log the string'Hello world'
goodbye
should log the string'Goodbye world'
- Use your
repeat
function to call thehello
function five times:repeat(hello, 5)
- Use your
repeat
function to call thegoodbye
function five times:repeat(goodbye, 5)
-
Create a function called
createGreeter
which takes a single string argument,greeting
-
createGreeter
should return a function -
The function which is returned should take a single argument,
name
-
The function which is returned should log the greeting and name combined. So if
greeting
was'Bonjour'
, andname
was'Sofia'
the function should log'Bonjour Sofia'
. -
Create a "Hello" greeter by calling the
createGreeter
function, passing'Hello'
as thegreeting
argument. -
Create a "Bonjour" greeter by calling the
createGreeter
function, passing'Bonjour'
as thegreeting
argument -
Call your two greeters, passing the names
'Anna'
and'Sofia'
as thename
argument. Your output should be:Hello Anna Bonjour Sofia
- A turtle's movements can be represented by an array which looks like this:
[3, 4]
. The first item in the array represents the number of steps the turtle takes forwards. The second number in the array is the number of steps the turtle takes to the left. - Here is an array of different movements made by a turtle:
[[0, 0], [0, 5], [-1, -3], [-3, 1], [2, -4], [3, 2]]
. - Use the
filter
method to remove any items where the turtle moves backwards or to the right (i.e. where either the first of second number is an item is negative). - Use the
map
method to create a new array containing how many steps the turtle makes in total with each movement (i.e. the first and second number added together). - Use the
forEach
method to log out how many steps the turtle took in each case.