Tell us what’s happening:
I’m a little confused on why my code isn’t working. I’ve been stuck on this challenge for days!
any Help or suggestions is appreciated!!
You also are returningbackwards.join("") from the function palindrome, and then ending the function declaration prematurely with a }. Later, your code seems to want palindrome(str) to return a boolean.
One more syntax/logic error: your if statement (now outside of the function palindrome(str)), is calling palindrome(str), and then following the if (condition) with a semicolon before the curly braces.
You need to move the logic inside the function - it isn’t going to work if you have logic floating around. Everything thould be part of the palindrome function. The function should accepts a string, and return true or false. At the minute you have a function called palindrome that just reverses a string, then some logic outside it that can’t work.
[minor] You don’t need to initialise an array (var array = [];) - str.split creates an array anyway, so var array = str.split("") is fine.
There’s a gap here: array. reverse()
related to point 1, this if (backwards.join("") === palindrome ("")) doesn’t make sense. You’ve already join-ed backwards, and you can’t then join a string. And palindrome("") is just calling the function palindrome with an empty string.
Once you’ve fixed these things, you’re still going to have a problem: something like eye will work, it’ll return true as a palindrome. But Eye is a palindrome, and that will return false. And what about A man, a plan, a canal, Panama - that’s a palindrome as well, but a fixed version of your logic will return false.