mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-30 16:01:14 -04:00
feat: add Implement a Pig Latin Translator lab (#62128)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Anna <a.rcottrill521@gmail.com>
This commit is contained in:
@@ -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": [
|
||||
|
||||
@@ -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.
|
||||
@@ -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;
|
||||
}
|
||||
```
|
||||
15
curriculum/structure/blocks/lab-pig-latin.json
Normal file
15
curriculum/structure/blocks/lab-pig-latin.json
Normal file
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user