---
description: >-
  Algorithm Challenge to practice strategies to solve problems in a methodical
  manner.
---

# Palindrome Challenge

## **Summary / Overview**

**Our goal is to create a simple app that lets a user type in a word and returns true if it is a palindrome.**&#x20;

A _palindrome_ is a word a word that is spelled the same forwards and backwards Ex:

* _racecar_
* _tacocat_
* _anna_

Using our function:

{% tabs %}
{% tab title="Index.js" %}
```javascript
isPalindrome('racecar');
// True

isPalindrome("tacocat")
//True

isPalindrome("anna")
//True

isPalindrome("Peter")
//False
```
{% endtab %}
{% endtabs %}

**The above would all return True**

Let's dive in to this challenge and try to tackle the palindrome problem.&#x20;

## **Setup**

Create a new directory called **palindrome**.  Inside the directory create **index.html** and **index.js** files.

## **Implementation**

In the **index.js** file write a function called **isPalindrome()**.  There are several String and Array methods commonly used to solve this problem, but for our purposes we will not be using them

#### Contraints

* Cannot use string or array methods
* isPalendrome must take in a string and return true or false

## **Step One**

#### Check against the following use cases:

{% tabs %}
{% tab title="index.js" %}
```javascript
isPalindrome('racecar');
isPalindrome('tacocat');
isPalindrome('anna');
```
{% endtab %}
{% endtabs %}

Once you have passed the above test cases, move on to the next step

## Step Two

### Edge Cases and Refactoring

Inspect your code and look for edge cases where your algorithm does not work. As an engineer you want to think of all the way your program can break and how we can prevent it. Think about how your _isPalindrome_ function can fail  Some example edge cases for this problem would be:

* Does it fail with numbers?&#x20;
* Does it work with spaces?
* If a string has punctuation does that work?\


You do not have to code up all the edge cases for this exercise but try to think about what can do wrong.

After thinking about some edge cases is there any way you can **refactor** your code to have less steps, are you repeating any code (DRY) or can we make it more readable and understandable. We never have a perfect solution to a problem in our code on the first attempt.&#x20;

Once you are happy with your refactored _isPalindrome_ function and thought about ways your code can break move on to the next step.

## Step Three

### Adding a User Interface ( UI )

{% hint style="warning" %}
The previous steps must be completed first.
{% endhint %}

Now that you have working **algorithm** for detecting if a string is a palindrome lets build a User Interface for it.

#### User Stories / Requirements

In programming we describe a programs functionality through **User Stories.** This helps software engineers relate to how the application they are building will be used by the end user. They can also be thought of as application requirements.

#### Palindrome App User Stories / Requirements



* As a user I would like to be able to type a word on the page.
* As a user I would like to be able to submit this word to be checked if it is a palindrome
* As a user I would like the words I submit to be saved in a palindrome or not palindrome list
* As a user I would like this list to persist until I refresh the page.

{% hint style="info" %}
Complete the user stories in order and break down the steps further into smaller steps if needed.
{% endhint %}

## DEMO Palindrome UI

Feel free to add some extra css to make it look nice

![Palindrome App](https://lh5.googleusercontent.com/vdLsL_Pk4ldbKAXi7usrwXaBTzdXGSYk4lztV21Mv3eBlpDvY--QIFJJYqfNAY6b2SG3CR2DusSQS9ozIGDuuRTvPoRv39DfjEaEe1ef5x4qaijianSSHxIYmwrwjWJf6HxeNE8w)

Let's dive in to this challenge first and foremost. Partner up with someone and take the next 15 minutes to come up with ideas on how to solve the following algorithm challenge.

{% hint style="warning" %}
During this exercise focus on writing pseudo code and not actual functional code
{% endhint %}

