Confirm the Ending: algorithm scripting

Confirm the Ending: algorithm scripting
0

#1

Tell us what’s happening:

It works in the case of “true” but when it comes to “false” it wouldn’t work.

Your code so far


function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  let arr =str.split(" ");
  let num = arr.length;
  if(arr[arr.length-1]= target){
    return true;
  }
 else {
   return false;
 }
};

confirmEnding("Bastian", "n");

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending


#2

The problem is in the line containing your if statement. Look at it carefully and recall the difference between a comparison operator and an assignment operator.


#3

Pay attention to what @ArielLeslie told you.

Also, arr.length will always be 1 because you’re splitting the string using a space, and words don’t have spaces.

Oh, and the target could have more than one character. Take this into account when you fix the condition inside the if statement.