Skip to content

Commit

Permalink
JS1-week4 | investigate folder: find.js
Browse files Browse the repository at this point in the history
  • Loading branch information
pedram-am committed Dec 19, 2023
1 parent 382453e commit fe85bb2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions week-4/investigate/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,25 @@ console.log(find("code your future", "z"));
// b) What is the if statement used to check
// c) Why is index++ being used?
// d) What is the condition index < str.length used for?

// a):

// The index variable is initially set to 0.
// Inside the while loop, index is incremented by 1 in each iteration using the index++ statement.
// The purpose is to move through each character in the string, checking if it matches the target character.

// b):

// The if statement is checking if the character at the current index in the string (str[index]) is equal to the target character (char).
// The condition is if (str[index] === char). If this condition is true, it means the target character is found at the current index.

// c):

// index++ is the post-increment operator, and it is used to increment the index variable by 1 after each iteration of the loop.
// This is necessary to move to the next character in the string and avoid an infinite loop.

// d):

// The condition index < str.length is used as the loop condition.
// The loop continues to iterate as long as the current value of index is less than the length of the string (str.length).
// This ensures that the loop iterates through each character in the string, and it prevents going beyond the bounds of the string.

0 comments on commit fe85bb2

Please sign in to comment.