Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial



I need to write js code that can see if a word is a palindrome but must be done with the function .slice and can not use loops or arrays. can someone help? don't now how to begin.

const isPalindrome = str => {

Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,671 Points

Why are you limited to using .slice? Sounds like a school assignment ...

Rich Donnellan

it is a school assignment it is an extra out of the obligatory but would like to be able to do this but do not understand the logic with the slice function with a for loop I can do it too but unfortunately it can not be used.

so I thought I was going to hear if treehouse community can help me with this problem.

1 Answer

Hi Conor!

These limitations ask for some gold and old recursion: https://en.wikipedia.org/wiki/Recursion

You don't need to check all the letters of a word at the same time to discover a palindrome. Just two are necessary: the first and the last. If they are different, the word for sure is not a palindrome. Perceive that the word with the first and last letters removed must be a palindrome too!

'arara' => 'rar' => 'a' all are palindrome.
'twittiwt' => 'wittiw' => 'itti' => 'tt' all are palindrome too!
'wolf' is not a palindrome :/
'sims' => 'im' is not a palindrome :(

I hope this helps! :)

Thx JucΓ©lio this certainly helps but do not know how I can take a last character if the word can be longer or shorter than a number of letters so start = 0 but the end =?

Hey Conor!

You can use the str.slice(-1); to extract the last character. Please check the MDN Documentation for more information about negative numbers as parameter.