You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-3/4-stretch/find.js
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,15 @@ console.log(find("code your future", "z"));
20
20
// Pay particular attention to the following:
21
21
22
22
// a) How the index variable updates during the call to find
23
+
// index starts at 0.
24
+
// The while loop runs as long as index is less than the string length.
25
+
// Inside the loop, if the character at index matches the target, the function returns that index.
26
+
// If it does not match, index increases by 1 and the loop checks again.
27
+
// This continues until the character is found or the end of the string is reached.
23
28
// b) What is the if statement used to check
29
+
// The if statement checks the character at the current index, and if it matches the target character, it returns the character index (position in the string).
24
30
// c) Why is index++ being used?
31
+
// index++ increases the index by 1 so the loop can check the next character in the string.
25
32
// d) What is the condition index < str.length used for?
33
+
// index < str.length ensures the loop runs only while the index is within the string length.
34
+
// It stops the loop when the end of the string is reached.
0 commit comments