Basic Algorithm Scripting - Confirm the Ending

So, I wrote my code, manually checked all cases from the task - and even though each of them returned what it should, every single tasks was marked with an x and i simply dont know why ( i know it ‘may’ not be best quality code )

function confirmEnding(str, target) {
  strArr=str.split("")
  diff=strArr.length-target.length
  strArr.splice(0,diff)
  return target==strArr.join("")
}

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/109.0.0.0 Safari/537.36 OPR/95.0.0.0

Challenge: Basic Algorithm Scripting - Confirm the Ending

Link to the challenge:

Do you see this error in the console?

ReferenceError: assignment to undeclared variable strArr

Forgot the “let” and wasted an hour+… sorry, definitely not my day, didnt mean to waste ur time bro

No waste of time - we’re here to answer questions

(post deleted by author)

the slice() method may be better than the splice() method so that you are not modifying the original array itself when you extract the values. But to use the slice() method, you would then need to modify your code to slice from the end using negative index.

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