At start writes an error: “countTarget.join is not a function”. Although the function is written correctly.
function confirmEnding(str, target) {
var countTarget = ;
for(var i = 0; i < target.length; i++){
countTarget = i;
var number = countTarget.length;
}
var anyString = str.substring(str.length - number);
var answer;
if (anyString == countTarget.join(’’))
{answer = true;}
else {answer = false; }
return answer;
}
confirmEnding(“Bastian”, “n”);
**Your browser information:**
User Agent is: `Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 YaBrowser/19.6.2.599 Yowser/2.5 Safari/537.36`.
**Link to the challenge:**
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending
Thank you very much.
Now the problem with the if statement. if I put the = sign, the condition is satisfied true. If i put sign == the condition is satisfied false
No, if you use = you are assigning what is to the right of it to the left of it, when you use == you are comparing the two things and is evaluated as a boolean
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
Well, could you explain me what you want to do with each line of code? There are few weird things but I would need to be sure what you want to do with them
I wanted to add this reply to the solutions page because it seems more concise than what is solutions are on the solutions page. However, I don’t know how to reply to the solutions page.
Here’s my solution:
function confirmEnding(str, target) {
return str.slice(-target.length) == target;
}