My code works fine in console log but does not pass test

Sorry for making another post so quickly but this is strange.

I’ve tested all the requirements in console log and the code works fine but it’s not passing any of them.

Your code so far

function confirmEnding(str, target) {
  endingLetters = str.slice(-Math.abs(target.length))
    if(target === endingLetters) {
      return true
    } else {
      return false

console.log(confirmEnding("Open sesame", "same"));

Your browser information:

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

Challenge: Basic Algorithm Scripting - Confirm the Ending

Link to the challenge:

The fCC environment is strict about syntax and defining variables correctly.

When I paste your code into the editor I see this error pop up

“ReferenceError: endingLetters is not defined”

So you need to add the appropriate keyword to define this variable correctly.

so, is replacing endingLetters with str appropriate?

It passed the test, but I thought I heard somewhere that you shouldn’t redefine parameters or something along those lines. Maybe I’m not remembering correctly.

no that is not a good strategy. (you should not modify input parameters unless that is the explicit purpose of the function)

You are just missing a key word in front of the variable endingLetters…

The missing keyword is let.

Oh wow, I can’t believe I missed that lol.

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