Why doesn't my formula work?

Tell us what’s happening:
Describe your issue in detail here.
I’m using str.slice(-1) === target
Why doesn’t this work? It equates the final element of the str string with target as either true or false. This is what the challenge requests, right?

What am I missing here?

Thanks!

Your code so far


function confirmEnding(str, target) {

return str.slice(-1) === target ? true : false;
}

confirmEnding("Bastian", "n");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36

Challenge: Confirm the Ending

Link to the challenge:

Lol… would be nice if it were that simple.
Unfortunately it doesn’t specify that target need only be one character long.

3 Likes

your function only checks the last char of the string and compare it to the target. You want to check the length of the target and use it as a slice argument. BTW when a boolean must return if its true or false, you can return the boolean directly; no need to tell if its true, return true, if its false, return false.

1 Like

Hello, you should think about the “target” string.

Target string not always “n”.

Target, sometimes “same”, “action” or something different string value.

So you can’t compare with str.slice(-1) right ? for example

let str = “Bastian” and let target = “tian”

str.slice(-1) returns you to “n”, and you can’t compare with “tian”

My advice is to find a way to split the words, break them apart, put them back together and compare them. I don’t wanna give you to direct solution :3

1 Like

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