Hi everyone,
I want to solve this challenge on my own without looking at solutions, please could you provide relevant links that could help me to work this challenge out by myself?
It says This challenge can be solved with the .endsWith() method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead----But there are no links to substrings methods, and the hint only leads to the solution
I feel like I am always looking at solutions and not able to write my own
Your code so far
function confirmEnding(str, target) {
return str;
}
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/81.0.4044.138 Safari/537.36.
first, str.legth is wrong, it is spelled str.length.
The only reason for which it returns true correctly it is because the for loop doesn’t execute for this spelling error.
Then, inside the loop you have myCheck = str[i].slice(target) which doesn’t have much sense. First, because str[i] is one single character, and second because slice takes one or more arguments but these arguments should be numbers. I suggest you return where you learned about slice or read the documentation about it.
And then, you assign it to myCheck, which was originally a boolean, and now it isn’t anymore.
I suggest you try again with something a bit more planned out. If you had to do this with pen and paper, how would you do it?
Thank you.
I corrected the spelling mistake with length. Now it does not work for any of the conditions.
slice() takes two parameters -
wich are numbers so which numbers should I use here?, since I dont get where is the end of the str
with pen and peper i would use:
myCheck = str[i].slice(0,9)
on pen and paper slice()
will be to copy or extract the contents of each string to a new string but with a true or false depending on the end of the string.
I am lost, I dont know what to do , what math should I follow, is there any math() for this challenge?
Or I should look at the solution and understand what is doing?
The challenge should provide steps to follow or hints that lead me in the right path
But I am aware I need to come up with this myself, it is very difficult for me as I am a begginer
Thanks for you help!!
you have still various issues, I suggest you delete what you have, and try again.
what are you doing with str.length[i]-target.length? str.length is a number, it doesn’t have anything that you can access with indexes
Like, str[i] is a string of length one, it doesn’t have sense to use slice on it
so, I suggest, try to delete everything and do things step by step
I did, and I decided to look at the article that provides the sol with substr()
I did not know that you have to use within the if statement -target.length to count the number from the end of the string.
function confirmEnding(str, target) {
if(str.substr(-target.length) === target) {
return true;
} else {
return false;
}
}
confirmEnding(“Bastian”, “n”);
I think it was better I looked it up. Now I can define steps by steps in the next challenge.