JavaScript
JavaScript String Type
Includes
We can check whether a string contains another string by using the
method includes. This method returns a Boolean value.
const title = "The Lies of Locke Lamora"console.log(title.includes("Lies")) // true
Read more on MDN
String.prototype.includes()
Test yourself
Description
Define a new function with the name
isAmerican
that takes a string input parameter and checks whether the string contains
awesome
We do not care about the capitalization, and want it to return true
for any combination of upper and lower case variations of the search
word.
Tests
- 1
You should define a function named
isAmerican. - 2
isAmerican("This super mediocre thing was awesome!")should returntrue. - 3
isAmerican("Awesome, let us do that!")should returntrue. - 4
isAmerican("That sounds aWeSOme!")should returntrue. - 5
isAmerican("Brilliant!")should returnfalse. - 6
isAmerican("To us — richer and cleverer than everyone else!")should returnfalse.