Exercise · Functions · lesson 10 of 10
Exercise: repeat a word
Write a function function repeatWord(word, times, separator) that returns a string of times copies of the word word, separated by the string separator.
Give the last two parameters default values: times is 2, and separator is a space, " ".
repeatWord("la", 3, "-")→"la-la-la"repeatWord("hey")→"hey hey"repeatWord("go", undefined, "+")→"go+go"
Constraints: times is an integer from 0 to 10 or undefined, and for 0 the result is the empty string ""; separator is any string or undefined, and the empty string "" joins the copies with no separator.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.