console.log(confirmEnding(“Connor”, “n”));
returns true , Connor have two n’s and my function returns true but it should be false bcz n should be match only one time not twice according to the challenge . So tell me how to do it ?
**Your code so far**
function confirmEnding(str, target) {
var string= [];
string.push(str)
var result;
for(let i=0;i<string.length;i++){
if(string[i].includes(target)==true){
result = true;
}
else{
result = false;
}
}
return result
}
console.log(confirmEnding("Connor", "n"))
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36
includes is a very useful function, but not necessarily for this. Instead, can you think of some string functions that might let you pull a smaller string from a bigger one? A substring of str, if you will?
it seems you have misinterpreted the instructions, you are checking the ending of the string, the last character(s) of str must be equal to target for the function to return true
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.