Giter Site home page Giter Site logo

fcc_palindrome_checker's Introduction

fcc_palindrome_checker

FCC Algorithms and Data Structures required project for certification - Project 1/5

Build a Palindrome Checker A palindrome is a word or phrase that can be read the same way forwards and backwards, ignoring punctuation, case, and spacing.

Note: You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.

Objective: Build an app that is functionally similar to https://palindrome-checker.freecodecamp.rocks

User Stories:

  1. You should have an input element with an id of text-input
  2. You should have a button element with an id of check-btn
  3. You should have a div element with an id of result
  4. When you click on the #check-btn element without entering a value into the #text-input element, an alert should appear with the text Please input a value
  5. When the #text-input element only contains the letter A and the #check-btn element is clicked, the #result element should contain the text A is a palindrome
  6. When the #text-input element contains the text eye and the #check-btn element is clicked, the #result element should contain the text eye is a palindrome
  7. When the #text-input element contains the text _eye and the #check-btn element is clicked, the #result element should contain the text eye is a palindrome
  8. When the #text-input element contains the text race car and the #check-btn element is clicked, the #result element should contain the text race car is a palindrome
  9. When the #text-input element contains the text not a palindrome and the #check-btn element is clicked, the #result element should contain the text not a palindrome is not a palindrome
  10. When the #test-input element contains the text A man, a plan, a canal. Panama and the #check-btn element is clicked, the #result element should contain the text A man, a plan, a canal. Panama is a palindrome
  11. When the #text-input element contains the text never odd or even and the #check-btn element is clicked, the #result element should contain the text never odd or even is a palindrome
  12. When the #text-input element contains the text nope and the #check-btn element is clicked, the #result element should contain the text nope is not a palindrome
  13. When the #text-input element contains the text almostomla and the #check-btn element is clicked, the #result element should contain the text almostomla is not a palindrome
  14. When the #text-input element contains the text My age is 0, 0 si ega ym. and the #check-btn element is clicked, the #result element should contain the text My age is 0, 0 si ega ym. is a palindrome
  15. When the #text-input element contains the text 1 eye for of 1 eye. and the #check-btn element is clicked, the #result element should contain the text 1 eye for of 1 eye. is not a palindrome
  16. When the #text-input element contains the text 0_0 (: /-\ :) 0-0 and the #check-btn element is clicked, the #result element should contain the text 0_0 (: /-\ :) 0-0 is a palindrome
  17. When the #text-input element contains the text five|_/|four and the #check-btn element is clicked, the #result element should contain the text five|_/|four is not a palindrome

Fulfill the user stories and pass all the tests below to complete this project. Give it your own personal style. Happy Coding!

Approach : in order to solve this problem i will be applying the following :

String Methods to split, reverse and join

```
function checkPalindrome(str) {

    let opoStr = str.split('').reverse().join('');
    if (opoStr === str) {
    console.log('Palindrome');
}
    console.log('Not Palindrome');
}

checkPalindrome('eye');// Palindrome
checkPalindrome('madam');// Palindrome
checkPalindrome('fox');// Not Palindrome

    we need apply regex to check alsp replace all alphanumeric values and symbols.

    ```
    function checkPalindrome(str) {
    const regEx= /[\W_]/g; 
    const processedStr = str.toLowerCase().replace(regEx, '');

    let opoStr = processedStr.split('').reverse().join('');
    if (opoStr === processedStr) {
      console.log('Palindrome');
    } else {
      console.log('Not Palindrome');
        }
    }

    checkPalindrome('eye')
    checkPalindrome('-eye')
    checkPalindrome('My age is 0, 0 si ega ym.')
    checkPalindrome('five|\_/|four')    
    ```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.