WorksheetsJavaScript String Methods
Total questions: 15
Worksheet time: 10mins
let string = "foo"
How to determine the length of the string?
(a)
let string = "The cat is black"
How to find the index/position of "cat" in the string
(a)
let string = "The black cat is black"
How to find the LAST index/position of "black" in the string
(a)
let string = "Milk, chocolate, cookies"
How to extract a new string "chocolate, cookies" from the first string
(a)
let string = "Milk, chocolate, cookies"
How to replace "chocolate" with "banana"?
(a)
let string = "Milk, chocolate, cookies"
How to figure out what character is on the 3rd position of the string?
(a)
let string = "Milk, chocolate, cookies"
How to convert the string to upper case?
(a)
let string = "Milk, chocolate, cookies"
How to convert the string to lower case?
(a)
let string = " Hello World! "
How to trim the whitespaces around "Hello World!" ?
(a)
let stringOne = "Milk"
let stringTwo = "chocolate"
Which operations below can be used to make a new string that says: "Milk, chocolate" using the variables.
stringOne + ", " + stringTwo
stringOne + ', ' + stringTwo
`${stringOne}, ${stringTwo}`
stringOne.concat(", ", stringTwo)
all of the above
let string = "a, b, c, 1, 2, 3"
How to convert this string into the array: ["a", "b", "c", "1", "2", "3"]?
(a)
let string = "chocolate milk banana"
How to convert this string into the array: ["chocolate", "milk", banana"]?
(a)
let string = "chocolate milk banana"
what will happen to the string if we run the command:
let test = string.split(" ")
test is equal to the string words, split at every character
test is equal to 3 strings, each with one word
test is equal to an array with 3 words
test is equal to an array with 21 characters
let array = ["chocolate", "milk", "cookies"]
what happens when we run the command:
let string = array.join(" ")
string is equal to [chocolate, milk, cookies]
string is equal to "chocolate milk cookies"
string is equal to "chocolatemilkcookies"
string is equal to "chocolate", "milk", "cookies"
let string = "milk, chocolate, cookies"
How to get a boolean indicating if the string includes the word "cookies"
HINT: the command should return true or false
(a)
