diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 21081b36310..fef0cb6b910 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -3245,6 +3245,12 @@ "In this lab, you will practice dividing an array into smaller arrays with the technique of your choice." ] }, + "lab-repeat-a-string": { + "title": "Build a String Repeating Function", + "intro": [ + "In this lab, you will implement loops to repeat a string a specified number of times." + ] + }, "review-javascript-loops": { "title": "JavaScript Loops Review", "intro": [ diff --git a/client/src/pages/learn/full-stack-developer/lab-repeat-a-string/index.md b/client/src/pages/learn/full-stack-developer/lab-repeat-a-string/index.md new file mode 100644 index 00000000000..a67b790502d --- /dev/null +++ b/client/src/pages/learn/full-stack-developer/lab-repeat-a-string/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to the Build a String Repeating Function +block: lab-repeat-a-string +superBlock: full-stack-developer +--- + +## Introduction to the Build a String Repeating Function + +In this lab, you will implement loops to repeat a string a specified number of times. diff --git a/curriculum/challenges/_meta/lab-repeat-a-string/meta.json b/curriculum/challenges/_meta/lab-repeat-a-string/meta.json new file mode 100644 index 00000000000..341a56c0aa1 --- /dev/null +++ b/curriculum/challenges/_meta/lab-repeat-a-string/meta.json @@ -0,0 +1,11 @@ +{ + "name": "Build a String Repeating Function", + "isUpcomingChange": false, + "dashedName": "lab-repeat-a-string", + "superBlock": "full-stack-developer", + "helpCategory": "JavaScript", + "challengeOrder": [{ "id": "afcc8d540bea9ea2669306b6", "title": "Build a String Repeating Function" }], + "usesMultifileEditor": true, + "blockType": "lab", + "blockLayout": "link" +} diff --git a/curriculum/challenges/english/25-front-end-development/lab-repeat-a-string/afcc8d540bea9ea2669306b6.md b/curriculum/challenges/english/25-front-end-development/lab-repeat-a-string/afcc8d540bea9ea2669306b6.md new file mode 100644 index 00000000000..f5e1c06be1b --- /dev/null +++ b/curriculum/challenges/english/25-front-end-development/lab-repeat-a-string/afcc8d540bea9ea2669306b6.md @@ -0,0 +1,105 @@ +--- +id: afcc8d540bea9ea2669306b6 +title: Build a String Repeating Function +challengeType: 26 +dashedName: build-a-string-repeating-function +--- + +# --description-- + +In this lab, you will create a function that repeats a given string a specific number of times. For the purpose of this lab, do _not_ use the built-in `.repeat()` method. + +**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. + +**User Stories:** + +1. You should create a function named `repeatStringNumTimes` that takes two parameters: a string and a number. +2. The function should return the string repeated the specified number of times. +3. If the number is less than or equal to zero, the function should return an empty string. + +# --hints-- + +You should create a function named `repeatStringNumTimes`. + +```js +assert.isFunction(repeatStringNumTimes); +``` + +`repeatStringNumTimes` should take two parameters. + +```js +assert.lengthOf(repeatStringNumTimes, 2); +``` + +The function `repeatStringNumTimes` should always return a string. + +```js +assert.isString(repeatStringNumTimes('hello', 3)); +``` + +`repeatStringNumTimes("*", 3)` should return the string `***`. + +```js +assert.strictEqual(repeatStringNumTimes('*', 3), '***'); +``` + +`repeatStringNumTimes("abc", 3)` should return the string `abcabcabc`. + +```js +assert.strictEqual(repeatStringNumTimes('abc', 3), 'abcabcabc'); +``` + +`repeatStringNumTimes("abc", 4)` should return the string `abcabcabcabc`. + +```js +assert.strictEqual(repeatStringNumTimes('abc', 4), 'abcabcabcabc'); +``` + +`repeatStringNumTimes("abc", 1)` should return the string `abc`. + +```js +assert.strictEqual(repeatStringNumTimes('abc', 1), 'abc'); +``` + +`repeatStringNumTimes("*", 8)` should return the string `********`. + +```js +assert.strictEqual(repeatStringNumTimes('*', 8), '********'); +``` + +`repeatStringNumTimes("abc", -2)` should return an empty string (`""`). + +```js +assert.isEmpty(repeatStringNumTimes('abc', -2)); +``` + +`repeatStringNumTimes("abc", 0)` should return `""`. + +```js +assert.isEmpty(repeatStringNumTimes('abc', 0)); +``` + +The built-in `repeat()` method should not be used. + +```js +assert.notMatch(__helpers.removeJSComments(code), /\.repeat/g); +``` + +# --seed-- + +## --seed-contents-- + +```js + +``` + +# --solutions-- + +```js +function repeatStringNumTimes(str, num) { + if (num < 1) return ''; + return num === 1 ? str : str + repeatStringNumTimes(str, num - 1); +} + +repeatStringNumTimes('abc', 3); +``` diff --git a/curriculum/superblock-structure/full-stack.json b/curriculum/superblock-structure/full-stack.json index efd98d07d4c..2da823a467b 100644 --- a/curriculum/superblock-structure/full-stack.json +++ b/curriculum/superblock-structure/full-stack.json @@ -704,6 +704,7 @@ }, { "dashedName": "lab-mutations" }, { "dashedName": "lab-chunky-monkey" }, + { "dashedName": "lab-repeat-a-string" }, { "dashedName": "lab-profile-lookup" },