Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Exercise 06 - repeatString

Write a function that simply repeats the string a given number of times:

repeatString('hey', 3) // returns 'heyheyhey'

This function will take two arguments, string and num. If num is a negative number, return the string 'ERROR' instead.

Use loops to implement repeatString rather than using the builtin String.prototype.repeat which has the same behaviour.

Note: The exercises after this one will not have arguments provided as this one does - you will need to provide them yourself from now on. So read each exercise's README carefully to see what kinds of arguments will be expected.

Hints

  • What inputs does the function need to achieve its goal?

  • How can you iteratively build up the final string, using one of the inputs to control the repetition?