QUESTION IMAGE
Question
jump to level 1
loop through the characters in the string oldproverb and assign timesoccurred with the number of times i appears in the string.
note: your code will be tested with more values for oldproverb.
1 let oldproverb = \all good things must come to an end.\;
2 let timesoccurred = 0;
3
4 / your solution goes here /
5
Step1: Initialize a loop
Use a for loop to iterate through each character in the oldProverb string.
for (let i = 0; i < oldProverb.length; i++) {
Step2: Check for 'i'
Inside the loop, check if the current character (accessed via oldProverb[i]) is equal to 'i'. If it is, increment the timesOccurred variable.
if (oldProverb[i] === 'i') {
timesOccurred++;
}
}Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
let oldProverb = "All good things must come to an end.";
let timesOccurred = 0;
for (let i = 0; i < oldProverb.length; i++) {
if (oldProverb[i] === 'i') {
timesOccurred++;
}
}