diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 83d2ec8841b..69f4c25ccdd 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -3737,6 +3737,13 @@ "title": "Build a RegEx Sandbox", "intro": ["In this lab you'll build a regex sandbox."] }, + "lab-pig-latin": { + "title": "Implement a Pig Latin Translator", + "intro": [ + "In this lab, you'll implement a Pig Latin translator using JavaScript.", + "You'll practice string manipulation, conditional logic, and regular expressions." + ] + }, "lab-smart-word-replacement": { "title": "Build a Smart Word Replacement Function", "intro": [ diff --git a/client/src/pages/learn/full-stack-developer/lab-pig-latin/index.md b/client/src/pages/learn/full-stack-developer/lab-pig-latin/index.md new file mode 100644 index 00000000000..1e4a4453da1 --- /dev/null +++ b/client/src/pages/learn/full-stack-developer/lab-pig-latin/index.md @@ -0,0 +1,9 @@ +--- +title: Introduction to the Implement a Pig Latin Translator +block: lab-pig-latin +superBlock: full-stack-developer +--- + +## Introduction to the Implement a Pig Latin Translator + +In this lab, you'll implement a Pig Latin translator using JavaScript. You'll practice string manipulation, conditional logic, and regular expressions. diff --git a/curriculum/challenges/english/blocks/lab-pig-latin/aa7697ea2477d1316795783b.md b/curriculum/challenges/english/blocks/lab-pig-latin/aa7697ea2477d1316795783b.md new file mode 100644 index 00000000000..d3869b292d7 --- /dev/null +++ b/curriculum/challenges/english/blocks/lab-pig-latin/aa7697ea2477d1316795783b.md @@ -0,0 +1,98 @@ +--- +id: aa7697ea2477d1316795783b +title: Implement a Pig Latin Translator +challengeType: 26 +dashedName: lab-pig-latin +--- + +# --description-- + +Pig Latin is a way of altering English words by following specific transformation rules. + +**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. + +**User Stories:** + +1. You should create a `translatePigLatin` function that accepts one string as argument. +1. If the string argument begins with a consonant, your function should take the first consonant or consonant cluster, move it to the end of the word, add `ay` to it, and return the result. +1. If the string argument begins with a vowel, your function should add `way` at the end and return the result. +1. Your function should handle string arguments where the first vowel comes in the middle of the word and return the appropriately transformed string. +1. If the string argument has no vowels, your function should add `ay` at the end and return the result. + +Note: For the context of this lab, vowels are `a`, `e`, `i`, `o`, and `u`. The letter `y` is not considered a vowel. + +# --hints-- + +You should have a `translatePigLatin` function. + +```js +assert.isFunction(translatePigLatin); +``` + +`translatePigLatin("california")` should return the string `aliforniacay`. + +```js +assert.deepEqual(translatePigLatin('california'), 'aliforniacay'); +``` + +`translatePigLatin("paragraphs")` should return the string `aragraphspay`. + +```js +assert.deepEqual(translatePigLatin('paragraphs'), 'aragraphspay'); +``` + +`translatePigLatin("glove")` should return the string `oveglay`. + +```js +assert.deepEqual(translatePigLatin('glove'), 'oveglay'); +``` + +`translatePigLatin("algorithm")` should return the string `algorithmway`. + +```js +assert.deepEqual(translatePigLatin('algorithm'), 'algorithmway'); +``` + +`translatePigLatin("eight")` should return the string `eightway`. + +```js +assert.deepEqual(translatePigLatin('eight'), 'eightway'); +``` + +Should handle words where the first vowel comes in the middle of the word. `translatePigLatin("schwartz")` should return the string `artzschway`. + +```js +assert.deepEqual(translatePigLatin('schwartz'), 'artzschway'); +``` + +Should handle words without vowels. `translatePigLatin("rhythm")` should return the string `rhythmay`. + +```js +assert.deepEqual(translatePigLatin('rhythm'), 'rhythmay'); +``` + +# --seed-- + +## --seed-contents-- + +```js + +``` + +# --solutions-- + +```js +function translatePigLatin(str) { + if (isVowel(str.charAt(0))) return str + "way"; + let front = []; + str = str.split(''); + while (str.length && !isVowel(str[0])) { + front.push(str.shift()); + } + return [].concat(str, front).join('') + 'ay'; +} + +function isVowel(c) { + return ['a', 'e', 'i', 'o', 'u'].indexOf(c.toLowerCase()) !== -1; +} +``` diff --git a/curriculum/structure/blocks/lab-pig-latin.json b/curriculum/structure/blocks/lab-pig-latin.json new file mode 100644 index 00000000000..976b7fde6c2 --- /dev/null +++ b/curriculum/structure/blocks/lab-pig-latin.json @@ -0,0 +1,15 @@ +{ + "name": "Implement a Pig Latin Translator", + "blockType": "lab", + "blockLayout": "link", + "isUpcomingChange": false, + "usesMultifileEditor": true, + "dashedName": "lab-pig-latin", + "challengeOrder": [ + { + "id": "aa7697ea2477d1316795783b", + "title": "Implement a Pig Latin Translator" + } + ], + "helpCategory": "JavaScript" +} diff --git a/curriculum/structure/superblocks/full-stack-developer.json b/curriculum/structure/superblocks/full-stack-developer.json index b331677385b..978a1c01c7c 100644 --- a/curriculum/structure/superblocks/full-stack-developer.json +++ b/curriculum/structure/superblocks/full-stack-developer.json @@ -456,6 +456,7 @@ "lab-palindrome-checker", "lab-markdown-to-html-converter", "lab-regex-sandbox", + "lab-pig-latin", "lab-smart-word-replacement", "review-javascript-regular-expressions", "quiz-javascript-regular-expressions"