Comparing two unequal string return true

Tell us what’s happening:
Describe your issue in detail here.

i am comparing a string[index] to anotherstring[index] but it return true while it should return false

  **Your code so far**

function confirmEnding(str, target) {
debugger;
let count = 0;
for(let i = target.length; i > 0; i-- ){
  let st = str.length - target.length;
  let t = i - target.length;
  if(str[st] === target[t]); // there is a problem with this compare
    console.log(`${str[st]} was equal to ${target[t]}`)
    // OUTPUT: r was equal to n 
    // This is superConfusing
    count++;
}
return count === target.length ? true : false;
}
confirmEnding("Connor", "n");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0

Challenge: Confirm the Ending

Link to the challenge:

Next time you post asking for help, please describe your issue in the part that says describe your issue in detail here.


The syntax is a little off here, so it’s not working as you expect it. You can review the if statement here:

i got it. i did not used the curly braces after the loop. that why it was not working

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.