Skip to content

Commit ec34846

Browse files
committed
find.js updated
1 parent 94de70c commit ec34846

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sprint-3/3-stretch/find.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ console.log(find("code your future", "z"));
2020
// Pay particular attention to the following:
2121

2222
// a) How the index variable updates during the call to find
23+
//The variable index starts at 0 and increases by 1 every time the loop runs (index++).
24+
//It keeps track of the current position in the string.
2325
// b) What is the if statement used to check
26+
//The if statement checks whether the current character (str[index]) is equal to the one we’re searching for (char).
27+
//If it is, we immediately return index.
2428
// c) Why is index++ being used?
29+
//It moves to the next character in the string during each loop iteration.
30+
//Without it, the loop would never move forward — it would keep checking the same character forever (infinite loop 🔁
2531
// d) What is the condition index < str.length used for?
32+
//That’s the loop condition — it keeps the loop running as long as index is less than the length of the string.
33+
//Once index equals str.length, it means we’ve checked every character, and the loop stops.

0 commit comments

Comments
 (0)