My Code:
I tried the following code
var str = "Have fun storming the castle!"
var character = "!";
function endsWith(str, character) {
return str.indexOf(character, str.length - character.length) !== -1;
}
alert(endsWith(str, character));
It is giving the result as True
since such word is present in the sentence.
But I need the result as castle!
as it is the only word having such character atlast. If multiple words having such character also, I need those words.