Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="top-half">
  <form id="top-half-content">
    <label for="palindrome-check">Is it a palindrome?</label>
    <input id="palindrome-check" type="text" name="palindrome-check" placeholder="Ex: Racecar">
  </form>
</div>

<div id="bottom-half">
  <p id="output">Nothing's been entered...</p>
</div>
              
            
!

CSS

              
                /*Variables*/
$primary-default: #152B42;
$primary-light: #1159A6;
$primary-dark: #152B42;

$primary-default-text: white;
$primary-light-text: black;
$primary-dark-text: white;

$font-family: 'Kufam', cursive;

/*Styles*/
body {
  font-family: $font-family;
  margin: 0;
  padding: 0;
}

#top-half {
  //Layout
  position: relative;
  width: 100vw;
  height: 50vh;
  min-height: 200px;
  
  //Text
  line-height: 50vh;
  
  //Design
  color: $primary-default-text;
  background-color: $primary-default;
  
  form {
    //Layout
    position: relative;
    display: inline-block;
    width: 100vw;
    height: 50vh;
    
    //Text
    text-align: center;
    line-height: 2rem;
    
    label {
      //Layout
      position: relative;
      width: 100vw;
      
      //Text
      font-size: 30px;
      font-weight: bold;
    }
    
    input {
      //Layout
      position: relative;
      width: 80%;
      height: 8vh;
      min-height: 40px;
      padding: 10px;
      
      //Text
      text-align: center;
      
      //Design
      border-radius: 20px;
      border: 0;
      outline: none;
      box-shadow: 0 0 5px black;
    }
  }
}

#bottom-half {
  //Layout
  position: relative;
  width: 100vw;
  height: 50vh;
  min-height: 200px;
  border: 1px solid;
  
  //Text
  font-size: 20px;
  line-height: 50vh;
  text-align: center;
  
  //Design
  color: $primary-dark;
  
  p {
    //Layout
    position: relative;
    display: inline-block;
    
    //Text
    line-height: 1.5rem;
  }
}
              
            
!

JS

              
                //Grab DOM objects
const palindromeCheck   = document.querySelector('#palindrome-check');  //The user input box
const output            = document.querySelector('#output');  //The output <p> tag

//Functions
let palindrome = (str) => {
  let alphaCheck = /[a-z0-9]/i;
  let alphaArr = str
    .toLowerCase()
    .split('')
    .filter(char => alphaCheck.test(char));
  if (alphaArr.length === 0) { return false; }
  for (let i = 0; i <= Math.floor(alphaArr.length/2); i++) {
    if (alphaArr[i] !== alphaArr[alphaArr.length - 1 - i]) {
      return false;
    }
  }
  return true;
};

let generateListeners = () => {
  palindromeCheck.addEventListener('input', generateOutput);
};

let generateOutput = (e) => {
  //Grab input
  let input = e.target.value;
  let inputArr = input.split(''); 
  
  //Ensure input is /[a-z0-9]/ only
  let inputTest = /[a-z0-9]/i;
  inputArr = inputArr.filter(char => inputTest.test(char));
  
  //Display clean text and continue
  e.target.value = inputArr.join('');
  input = inputArr.join('');
  
  if (input === '') { //Check to see if the input is empty
    output.textContent = "Nothing's been entered...";
  } else { //If it isn't, process input
    let checkValue = palindrome(input);

    if (checkValue) {
      console.clear(); console.log(output.target);
      output.textContent = "Yep, that's definitely a palindrome!";
    } else {
      output.textContent = "Nope, not a palindrome...";
    }
  }
};

//Generate listeners
generateListeners();
              
            
!
999px

Console