Skip to content

Commit d0371be

Browse files
committed
Update: comments foe questions to explain code in find.js for better clarity on loop mechanics
1 parent 4c03b27 commit d0371be

File tree

1 file changed

+5
-0
lines changed
  • Sprint-3/4-stretch-investigate

1 file changed

+5
-0
lines changed

Sprint-3/4-stretch-investigate/find.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ 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+
// increments by 1 in every iteration using index++.
2324
// b) What is the if statement used to check
25+
// checks if the character at the current index matches the specified character.
2426
// c) Why is index++ being used?
27+
// It moves the pointer forward through the string. Without it, the loop would run infinitely.
28+
2529
// d) What is the condition index < str.length used for?
30+
// It ensures we don’t read beyond the string boundary — this prevents errors or undefined behavior.

0 commit comments

Comments
 (0)