2018-10-08 17:34:43 +00:00
---
id: afcc8d540bea9ea2669306b6
title: Repeat a String Repeat a String
isRequired: true
challengeType: 5
2018-10-10 20:20:40 +00:00
videoUrl: ''
localeTitle: Repetir una cadena Repetir una cadena
2018-10-08 17:34:43 +00:00
---
## Description
2018-10-10 20:20:40 +00:00
< section id = "description" > Repetir una determinada cadena < code > str< / code > (primer argumento) para < code > num< / code > veces (segundo argumento). Devuelve una cadena vacía si < code > num< / code > no es un número positivo. Recuerda usar < a href = "http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514" target = "_blank" > Read-Search-Ask< / a > si te atascas. Escribe tu propio código. < / section >
2018-10-08 17:34:43 +00:00
## Instructions
2018-10-10 20:20:40 +00:00
< section id = "instructions" >
2018-10-08 17:34:43 +00:00
< / section >
## Tests
< section id = 'tests' >
```yml
tests:
2018-10-10 20:20:40 +00:00
- text: '< code > repeatStringNumTimes(" *" , 3)</ code > debe devolver < code > " ***" </ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert(repeatStringNumTimes("*", 3) === "***", "< code > repeatStringNumTimes("*", 3)< / code > should return < code > "***"< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > repeatStringNumTimes(" abc" , 3)</ code > debe devolver < code > " abcabcabc" </ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert(repeatStringNumTimes("abc", 3) === "abcabcabc", "< code > repeatStringNumTimes("abc", 3)< / code > should return < code > "abcabcabc"< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > repeatStringNumTimes(" abc" , 4)</ code > debe devolver < code > " abcabcabcabc" </ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert(repeatStringNumTimes("abc", 4) === "abcabcabcabc", "< code > repeatStringNumTimes("abc", 4)< / code > should return < code > "abcabcabcabc"< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > repeatStringNumTimes(" abc" , 1)</ code > debe devolver < code > " abc" </ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert(repeatStringNumTimes("abc", 1) === "abc", "< code > repeatStringNumTimes("abc", 1)< / code > should return < code > "abc"< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > repeatStringNumTimes(" *" , 8)</ code > debe devolver < code > " ********" </ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert(repeatStringNumTimes("*", 8) === "********", "< code > repeatStringNumTimes("*", 8)< / code > should return < code > "********"< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > repeatStringNumTimes(" abc" , -2)</ code > debe devolver < code > "" </ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert(repeatStringNumTimes("abc", -2) === "", "< code > repeatStringNumTimes("abc", -2)< / code > should return < code > ""< / code > .");'
- text: El método < code > repeat()</ code > incorporado no debe utilizarse
testString: 'assert(!/\.repeat/g.test(code), "The built-in < code > repeat()</ code > -method should not be used");'
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
function repeatStringNumTimes(str, num) {
// repeat after me
return str;
}
repeatStringNumTimes("abc", 3);
2018-10-10 20:20:40 +00:00
2018-10-08 17:34:43 +00:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2018-10-10 20:20:40 +00:00
// solution required
2018-10-08 17:34:43 +00:00
```
< / section >