Skip to content

Commit f1ac2fe

Browse files
committed
answered part b to d in find.js
1 parent b0265ba commit f1ac2fe

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
@@ -26,5 +26,13 @@ console.log(find("code your future", "z"));
2626
// Now, index is 1, and the while loop will check again, until the character is found or the index is no longer less than the length of the string.
2727

2828
// b) What is the if statement used to check
29+
// The if statement on line 5 checks if the character at current index of the string is equal to the target character (char).
30+
// If they are equal, the function returns the current index.
31+
2932
// c) Why is index++ being used?
33+
// The index++ on line 8 is being used to update the index variable by incrementing it by 1.
34+
// Given the character is not found at the current index, we need to move to the next index.
35+
3036
// d) What is the condition index < str.length used for?
37+
// The condition index < str.length on line 4 is used to ensure that the while loop continues to execute as long as the index is less than the length of the string.
38+
// More importantly, it prevents the while loop goes on forever into an infinite loop.

0 commit comments

Comments
 (0)