3.8 KiB
3.8 KiB
id, title, challengeType, videoUrl, forumTopicId
id | title | challengeType | videoUrl | forumTopicId |
---|---|---|---|---|
56533eb9ac21ba0edf2244bb | Word Blanks | 1 | https://scrimba.com/c/caqn8zuP | 18377 |
Description
var sentence = "It was really " + "hot" + ", and we " + "laughed" + " ourselves " + "silly" + ".";
Instructions
+
to build a new string, using the provided variables: myNoun
, myAdjective
, myVerb
, and myAdverb
. You will then assign the formed string to the wordBlanks
variable. You should not change the words assigned to the variables.
You will also need to account for spaces in your string, so that the final sentence has spaces between all the words. The result should be a complete sentence.
Tests
tests:
- text: <code>wordBlanks</code> should be a string.
testString: assert(typeof wordBlanks === 'string');
- text: You should not change the values assigned to <code>myNoun</code>, <code>myVerb</code>, <code>myAdjective</code> or <code>myAdverb</code>.
testString: assert(myNoun === "dog" && myVerb === "ran" && myAdjective === "big" && myAdverb === "quickly");
- text: You should not directly use the values "dog", "ran", "big", or "quickly" to create <code>wordBlanks</code>.
testString: const newCode = removeAssignments(code); assert(!/dog/.test(newCode) && !/ran/.test(newCode) && !/big/.test(newCode) && !/quickly/.test(newCode));
- text: <code>wordBlanks</code> should contain all of the words assigned to the variables <code>myNoun</code>, <code>myVerb</code>, <code>myAdjective</code> and <code>myAdverb</code> separated by non-word characters (and any additional words in your madlib).
testString: assert(/\bdog\b/.test(wordBlanks) && /\bbig\b/.test(wordBlanks) && /\bran\b/.test(wordBlanks) && /\bquickly\b/.test(wordBlanks));
Challenge Seed
var myNoun = "dog";
var myAdjective = "big";
var myVerb = "ran";
var myAdverb = "quickly";
// Only change code below this line
var wordBlanks = ""; // Change this line
// Only change code above this line
const removeAssignments = str => str
.replace(/myNoun\s*=\s*["']dog["']/g, '')
.replace(/myAdjective\s*=\s*["']big["']/g, '')
.replace(/myVerb\s*=\s*["']ran["']/g, '')
.replace(/myAdverb\s*=\s*["']quickly["']/g, '');
Solution
var myNoun = "dog";
var myAdjective = "big";
var myVerb = "ran";
var myAdverb = "quickly";
var wordBlanks = "Once there was a " + myNoun + " which was very " + myAdjective + ". ";
wordBlanks += "It " + myVerb + " " + myAdverb + " around the yard.";