1.7 KiB
1.7 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
587d7db3367417b2b2512b8e | Using the Test Method | 1 | 301369 |
Description
"the"
in the string "The dog chased the cat"
, you could use the following regular expression: /the/
. Notice that quote marks are not required within the regular expression.
JavaScript has multiple ways to use regexes. One way to test a regex is using the .test()
method. The .test()
method takes the regex, applies it to a string (which is placed inside the parentheses), and returns true
or false
if your pattern finds something or not.
let testStr = "freeCodeCamp";
let testRegex = /Code/;
testRegex.test(testStr);
// Returns true
Instructions
myRegex
on the string myString
using the .test()
method.
Tests
tests:
- text: You should use <code>.test()</code> to test the regex.
testString: assert(code.match(/myRegex.test\(\s*myString\s*\)/));
- text: Your result should return <code>true</code>.
testString: assert(result === true);
Challenge Seed
let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex; // Change this line
Solution
let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex.test(myString); // Change this line