Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                <header>
  <h1>Javascript projects!</h1>
</header>
<div class="card-container ">
  <div class="card reverse">
    <div class="cardTop reverse-background">
      <h3 class="cardTitle">Palindrome Checker</h3>
    </div>
    <div class="cardMiddle">
      <p>Enter a word, phrase, or symbols and find out if it is the same backwards as forwards.</p>
      <div class="input-container">
      <input type="text" id="palindromeText" placeholder="Taco cat">
      <button type="button" onclick="palindrome(document.getElementById('palindromeText').value)">Click here!</button>
        </div>
    </div>
    <div class="cardBottom">
      <div class="answer" data-animation="pop-in" id="palindromeAnswer"></div>
    </div>
  </div>
  
  <div class="card roman">
    <div class="cardTop roman-background">
      <h3 class="cardTitle">Roman Numeral Converter</h3>
    </div>
    <div class="cardMiddle">
      <p>Want to know what a regular number would be as a roman numeral?...(up to 9999. No comma please!)</p>
      <div class="input-container">
        <input type="text" id="romanText" placeholder="">
      <button type="button" onclick="convertToRoman(document.getElementById('romanText').value)">Click here!</button>
      </div>
    </div>
    <div class="cardBottom">
      <div class="answer" data-animation="pop-in" id="romanAnswer"></div>
    </div>
  </div>
  
  <div class="card decode">
    <div class="cardTop decode-background">
      <h3 class="cardTitle">Caesars Cipher</h3>
    </div>
    <div class="cardMiddle">
      <p>Enter a phrase encoded with a 
        <a href="https://en.wikipedia.org/wiki/ROT13" target="_blank">ROT13 cipher</a> in upper case and it shall be decoded.</p>
      <p>Examples to try:</p>
      <ul class="decode-list">
        <li>SERR CVMMN!</li>
        <li>QBA'G TB PUNFVAT JNGRESNYYF</li>
        <li>GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.</li>
      </ul>
      <div class="input-container">
        <input type="text" id="decodeText" placeholder="">
      <button type="button" onclick="rot13(document.getElementById('decodeText').value)">Click here!</button>
      </div>
    </div>
    <div class="cardBottom">
      <div class="answer" data-animation="pop-in" id="decodeAnswer"></div>
    </div>
  </div>
  
  <div class="card phone">
    <div class="cardTop phone-background">
      <h3 class="cardTitle">Telephone Number Validator</h3>
    </div>
    <div class="cardMiddle">
      <p>Enter a phone number to have the format verified.</p>
      <div class="input-container">
        <input type="text" id="phoneText" placeholder="">
      <button type="button" onclick="telephoneCheck(document.getElementById('phoneText').value)">Click here!</button>
      </div>
    </div>
    <div class="cardBottom">
      <div class="answer" id="phoneAnswer"></div>
    </div>
  </div>
  
  <div class="card cash">
    <div class="cardTop cash-background">
      <h3 class="cardTitle">Cash Register</h3>
    </div>
    <div class="cardMiddle">
      <p>This function will determine how much change to give and then give it back using the biggest tender available (so you don't get all pennies). The drawer is stocked with $350.41 for our example.</p>
      <div class="input-container">
        <input type="text" id="price" placeholder="Price of item">
      <input type="text" id="cash" placeholder="Cash given">
      
      <button type="button" onclick="checkCashRegister(document.getElementById('price').value, document.getElementById('cash').value)">Click here!</button>
      </div>
    </div>
    <div class="cardBottom">
      <div class="answer" id="cashAnswer"></div>
    </div>
  </div>
  
  <div id="web-credit">
      <p>See my full website at <a href="https://www.ryanbronkema.com/" target="_blank">RyanBronkema.com</a></p>
    </div>
              
            
!

CSS

              
                html,
body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
  background: #f2f2f2;}

p {
  padding: 5px;
  margin: 2px;}

input {
  font-size: 14px;}

button {
  font-size: 14px;
  background-color: #9fb8ad;
  color: #f2f2f2;
  border-color: gray;}

header {
  width: 100%;
  height: 50px;
  background-image: linear-gradient(
    141deg,
    #9fb8ad 0%,
    #1fc8db 51%,
    #2cb5e8 75%
  );
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;}

.card-container:before {
  content: "";
  width: 100%;
  height: 0;
  display: table;
  clear: both;}

.card-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around; }

.card {
  width: 400px;
  flex-wrap: wrap;
  box-shadow: 6px 6px 30px #aaa;
  box-sizing: border-box;
  margin: 23px;
  background: white;
  border: 2px solid black;}

.cardTitle {
  font-size: 1.7em;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.7);
  color: #222;}

.cardTop {
  display: flex;
  padding-top: 15px;
  padding-bottom: 150px;
}

.input-container {
  display: flex;
  justify-content: center;}

.more {
  text-align: center;}

.cardBottom {
  margin-top: 10px;
  min-height: 150px;
  width: 100%;}

.answer {
  display: none;
  padding: 40px;
  animation-name: popIn;
  animation-duration: 1s;
  height: 100%;
  text-align: center;
  font-size: 30px;
  word-wrap: break-word;}

.reverse-background {
  background: url(https://images.unsplash.com/photo-1531989417401-0f85f7e673f8?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=184b40faac8f1cc898b9b15cd2f782f2)
    no-repeat; }

.roman-background {
  background: url(https://images.unsplash.com/photo-1532166754810-780aaa2f2837?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=e02a09d8729b46c333833c39dd359ec9)
    no-repeat;
}

.decode-background {
  background: url(https://images.unsplash.com/photo-1533709752211-118fcaf03312?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=8c084fb41db5cbe2c5b88488f994b735)
    no-repeat;
}

.decode-list {
  list-style: none;
  margin-top: 0;
  padding-left: 25px;
}

.decode-list li {
  font-family: Inconsolata, monospace;
}

.phone-background {
  background: url(https://images.unsplash.com/photo-1534536281715-e28d76689b4d?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=56056d87e597e46c8dfeb085d20c4aa3)
    no-repeat;
}

.cash-background {
  background: url(https://images.unsplash.com/photo-1532629345422-7515f3d16bb6?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=0e3c238bc728926dd4aa838db9e645b5)
    no-repeat;
}

#web-credit {
  width: 100%;
  font-size: 14px;
  background-color: #2d2d30;
  padding: 10px;
  margin: 0px;
  text-align: center;
}

#web-credit p {
  margin: 0px;
  color: #f5f5f5;
}

#web-credit a {
  color: #f5f5f5;
}

#web-credit a:hover {
  color: #777;
  text-decoration: none;
}

@keyframes popIn {
  0% {
    transform: scale(0); }
  60% {
    opacity: 1;
    transform: scale(1.05); }
  80% {
    transform: scale(0.95); }
  100% {
    transform: scale(1);
    opacity: 1; } }

.animated.pop-in {
    animation: popIn 1s both; }
              
            
!

JS

              
                //1. Palindrome checker
function palindrome(str) {
  //Remove unnecessary characters
  let preppedStr = str.toLowerCase().replace(/[^a-z1-9]/g,"");

  //Save a reverse version of the prepped string
  let reversed = preppedStr.split("").reverse().join("");
  
  //Compare to see if prepped string is the same as the reversed one
  if (preppedStr === reversed){
 document.getElementById("palindromeAnswer").style.display = "block";   document.getElementById("palindromeAnswer").innerHTML = "That's totally a palindrome!";
  } else {
document.getElementById("palindromeAnswer").style.display = "block";   document.getElementById("palindromeAnswer").innerHTML = "Err nope. Not a palindrome.";
  }
}


//2. Roman Numeral Converter
function convertToRoman(num) {
  //Create arrays with the possible decimals and roman numerals. Also a variable to store the ongoing conversion. 
  let decimalArr = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
  let romanArr = ["M", "CM","D","CD","C", "XC", "L", "XL", "X","IX","V","IV","I"];
  let converted = "";

  //Loop over the decimal array from largest to smallest comparing largest num to see where it falls
  for (let i = 0; i <= decimalArr.length; i++){
      while (num % decimalArr[i] < num) {  
        converted += romanArr[i]; //add Roman numeral in same array position as decimal array
        num -= decimalArr[i];  //reduce the original num as we go
    }
  }
  document.getElementById("romanAnswer").style.display = "block";
  document.getElementById("romanAnswer").innerHTML = converted;
}


//3. Caesars Cipher
function rot13(str) {
    let newArr = str.toUpperCase();
    newArr = newArr.split("");
    //Loop through each character
    for (let i = 0; i < newArr.length; i++){
      //Convert each character to it's Unicode value as long as it's in the character range (not a space or punctuation). 
      //Add 13 if in the first half of the alphabet. 
      //Subtract 13 if in last half.
        if (str.charCodeAt([i]) < 78 && str.charCodeAt([i]) > 64) {
            let unicode = str.charCodeAt([i]) + 13;
            let newChar = String.fromCharCode(unicode);
            newArr.splice([i], 1, newChar);
        }
        else if (str.charCodeAt([i]) > 77 && str.charCodeAt([i]) < 101){
            let unicode = str.charCodeAt([i]) - 13;
            let newChar = String.fromCharCode(unicode);
            newArr.splice([i], 1, newChar);
        } else {
            //Else don't do anything!
        }
    }
 document.getElementById("decodeAnswer").style.display = "block";   document.getElementById("decodeAnswer").innerHTML = newArr.join("");
}


//4. Telephone Number Validator
function telephoneCheck(str) {
  let validOrNo = /^1*\s*((\(\d{3}\))|((-|\s)*\d{3}(-|\s)*))\s*\d{3}(-|\s)*\d{4}$/g
  
  if (validOrNo.test(str) === true){
 document.getElementById("phoneAnswer").style.display = "block";   document.getElementById("phoneAnswer").innerHTML = "Looks like a legit number to me!";
  } else {
document.getElementById("phoneAnswer").style.display = "block";   document.getElementById("phoneAnswer").innerHTML = "Sorry bro. She's just not that into you.";
  }
}


//5. Cash Register
function checkCashRegister(price, cash) {
  let cid = [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 60], ["TEN", 30], ["TWENTY", 60], ["ONE HUNDRED", 100]];
  let totalCid = 0;
  let changeDue = cash - price;
  let changeGiven = [];
  let currencyArr = [.01, .05, .1, .25, 1, 5, 10, 20, 100];
  let tally = 0;
  
  console.log(price);
  console.log(cash);
  if(price === cash){
    document.getElementById("cashAnswer").style.display = "block";       return document.getElementById("cashAnswer").innerHTML = "No change needed."
  };

//Sum up the cid into one amount
  for(let x = 0; x < cid.length; x++){
    totalCid += cid[x][1];
  }
 totalCid = Math.round(totalCid*100)/100;//Round to 2 decimal places to prevent rounding errors
 
//Check if there's enough money in the til to handle transaction
  if (changeDue === totalCid){
 document.getElementById("cashAnswer").style.display = "block";   return document.getElementById("cashAnswer").innerHTML = "Change given is all that's in the drawer."
  }

  for (let i = 8; i >= 0; i--){ //loop through currency array
    tally = 0;
    while (((changeDue / currencyArr[i]) >= 1) && (cid[i][1] > 0)) {
      tally += currencyArr[i];
      changeDue -= currencyArr[i];
      cid[i][1] -= currencyArr[i];
      totalCid -= currencyArr[i];
      changeDue = Math.round(changeDue*100)/100;//Round to 2 decimal places to prevent rounding errors
    }
    if(tally > 0){
      changeGiven.push([cid[i][0], tally]);
    }
    if (changeDue == 0){
 document.getElementById("cashAnswer").style.display = "block";        return document.getElementById('cashAnswer').innerHTML = "Here's your change, my friend " + changeGiven;
    } else if (changeDue > 0 && totalCid == 0){
 document.getElementById("cashAnswer").style.display = "block";        return document.getElementById('cashAnswer').innerHTML = "You need more change than I've got."
    } else if (i == 0 && changeDue >= 0.01){
 document.getElementById("cashAnswer").style.display = "block";        return document.getElementById('cashAnswer').innerHTML = "The drawer ran out of exact change. Sorry!"
    }
  }
}
              
            
!
999px

Console