Hey guys!
This loop i just wrote has checked every test except the following:
confirmEnding("Open sesame", "same")
should return true.
for some the if statement isnt executing. Why? The following tests are almost exactly the same but false (targets “game” and “sage”) and they checked, so i asume they do return the boolean after executing.
Another thing i’d like to ask is about the code itself. I checked the solution to see if the problem was something simple that i was missing and it made me realize that my code is kinda wacky compared to the very simple example. Should i be worried about it?
function confirmEnding(str, target) {
let i = 0;
while (i <= str.length - target.length) {
if (i === str.length - target.length) {
let ya = str.split(str[i-1]);
let hopeThisWorks = ya.pop();
console.log(hopeThisWorks);
return hopeThisWorks == target;
}
i++;
}
}
confirmEnding("Open sesame", "same");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
.
Challenge: Confirm the Ending
Link to the challenge: