Tell us what’s happening:
In for loop, I set the condition ‘i’ to be less than or equal to the length of the string, but ‘i’ never reaches the length. Hence, code does not pass the last condition of the test.
Why ‘i’ won’t reach 3 in this example?
Many thanks in advance.
Your code so far
function fearNotLetter(str) {
for(let i=0;i<=str.length;i++){
if(str.charCodeAt(i+1) - str.charCodeAt(i) !==1 ){
return String.fromCharCode(str.charCodeAt(i)+1)
}
/*i never reaches the length of the string, even though condition is set
to i <= str.length */
// console.log('i='+i)
//console.log(String.fromCharCode(str.charCodeAt(i)))
// console.log('array length='+str.length)
}
}
fearNotLetter("abc");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
.
Challenge: Missing letters
Link to the challenge: