1
2
3
4
5
6
7
8
9
10
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.
0,1,2,3,4,5,6,7,8,9
0
0
0
0
What is the keyword for finding the index of "h" in the first instance of "house"? | indexOf | indexOf | |
What is the keyword for finding the index of "B" in the last instance of "Bill"? | lastIndexOf | lastIndexOf | |
A string has been assigned to the variable str. Find the starting index of the first instance of "go" within the string. Assign the index number to the variable indx, which hasn't been declared beforehand. | let indx = str.indexOf("go"); | letindx=str\.indexOf\(•go•\); | |
A string has been assigned to the variable str. You're looking for the starting index of the last instance of a string segment assigned to the variable seg. Assign the index number to the variable indx, which hasn't been declared beforehand. | let indx = str.lastIndexOf(seg); | letindx=str\.lastIndexOf\(seg\); | |
A string has been assigned to the variable str. Find the starting index of the first instance of a segment inside the string. Assign the index number to another variable that hasn't been declared beforehand. Make up that variable name and the string you're looking for. | let segIndex = str.indexOf("xyz"); | let[a-z_$][a-zA-Z0-9_$]*=str\.indexOf\(•.*•\); | |
A string has been assigned to the variable str. Find the starting index of the last instance of a segment inside the string. Assign the index number to another variable that hasn't been declared beforehand. Make up the name of that variable and the string you're looking for. | let segIndex = str.lastIndexOf("xyz"); | let[a-z_$][a-zA-Z0-9_$]*=str\.lastIndexOf\(•.*•\); | |
Code the first line of an if statement that tests whether the segment "xyz" is found in aString. | if (aString.indexOf("xyz") !== -1) { | if\(aString\.indexOf\(•xyz•\)!==-1\){ | |
A string has been assigned to a variable. A segment you're looking for has been assigned to a second variable. Code an alert that displays the starting index of the first instance of the segment. Make up the variable names. | alert(paragraph.indexOf(segment)); | alert\([a-z_$][a-zA-Z0-9_$]*\.indexOf\([a-z_$][a-zA-Z0-9_$]*\)\); | |
|
|||
|