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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <!-- RESPONSIVE DOWN TO 300px WIDE -->

<noscript>
  <div style="
              width:100%;
              height:100%;
              color: #1E90FF;
              display: flex;
              align-items: center;
              justify-content: center;
              background-color: #FFD700;">
  <h1 style="margin:0">PLEASE ENABLE JAVASCRIPT</h1>
  </div>
  <style>
    .container {
      display: none;
    }
  </style>
</noscript><!-- END noscript -->

<div class="container">

  <div class="row">

    <nav>
      <ul id="menu">
        <li class="menu-item"><a href="#">menu</a></li>
        <li class="menu-item hidden"><a href="#">tools</a></li>
        <li class="menu-item hidden"><a href="#">trading</a></li>
        <li class="menu-item hidden"><a href="#">resources</a></li>
        <li class="menu-item hidden"><a href="#">transfers</a></li>
      </ul>
    </nav><!-- END menu -->

    <div class="icons">
      <i class="fas fa-balance-scale"></i>
      <i class="fas fa-calculator"></i>
      <i class="fas fa-percent"></i>
      <i class="far fa-chart-bar"></i>
      <i class="fas fa-chart-line"></i>
    </div><!-- END icons -->

    <h1 class="banner">Currency Converter</h1>

    <div class="column">

      <form action="" method="POST">

        <label for="amount">Amount:
          <input id="amount" name="amount" type="text" value="" placeholder="Amount" required>
        </label>

        <label for="rate">From:
            <select id="rate">
              <option value="USD">US Dollar (USD)</option>
              <option value="MXN">Mexican Peso (MXN)</option>
              <option value="XOF">Beninese CFA (XOF)</option>
              <option value="CAD">Canadian Dollar (CAD)</option>
              <option value="HTG">Haitian Gourde (HTG)</option>
              <option value="XBT">Bitcoin (BTC)</option>
              <option value="EUR">Cuban Peso (CUP)</option>
              <option value="GBP">British Pound (BGP)</option>
            </select>
          </label>

        <label for="to">To:
            <select id="to">
              <option value="MXN">Mexican Peso (MXN)</option>
              <option value="USD">US Dollar (USD)</option>
              <option value="XOF">Beninese CFA (XOF)</option>
              <option value="CAD">Canadian Dollar (CAD)</option>
              <option value="HTG">Haitian Gourde (HTG)</option>
              <option value="XBT">Bitcoin (BTC)</option>
              <option value="EUR">Cuban Peso (CUP)</option>
              <option value="GBP">British Pound (BGP)</option>
            </select>
          </label>

      </form><!-- END form -->

    </div><!-- END column -->

    <button class="btn" type="button">CALCULATE</button>

    <h2 class="amount"><span id="currency"></span><span id="total"></span><span id="country-code"></span></h2>

    <table id="hide">
      <thead>
        <tr>
          <th></th>
          <th>30 days</th>
          <th>90 days</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>high</td>
          <td>0.0249</td>
          <td>0.9826</td>
        </tr>
        <tr>
          <td>low</td>
          <td>0.0247</td>
          <td>0.9824</td>
        </tr>
        <tr>
          <td>average</td>
          <td>0.0248</td>
          <td>0.9825</td>
        </tr>
      </tbody>
    </table><!-- END table -->

  </div><!-- END row -->

</div><!-- END container -->
              
            
!

CSS

              
                /* RESPONSIVE DOWN TO 300px WIDE. */

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: 'Lato', sans-serif;
  background-color: #FFD700;
}

.container {
  width: 100%;
  height: 100%;
}

.row {
  width: 96%;
  height: 100%;
  margin: 0 auto;
}

nav {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: end;
      -ms-flex-pack: end;
          justify-content: flex-end;
}

#menu {
  width: 100%;
  padding-left: 0;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  list-style-type: none;
  -webkit-box-pack: end;
      -ms-flex-pack: end;
          justify-content: flex-end;
}

#menu:hover .hidden {
  display: block;
}

.menu-item {
  padding: 10px;
  margin-bottom: 1px;
  background-color: #333999;
}

.menu-item:hover {
  background-color: #5E67FF;
}

.hidden {
  display: none;
}

a {
  color: #FFFFFF;
  font-weight: bold;
  text-decoration: none;
}

.icons {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: end;
      -ms-flex-pack: end;
          justify-content: flex-end;
}

.icons i {
  color: #1E90FF;
  font-size: 24px;
  padding: 0 10px;
}

.column {
  width: 100%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
}

form {
  width: 100%;
  max-width: 425px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
}

label {
  width: 100%;
  -ms-flex-item-align: start;
      align-self: flex-start;
  font-weight: bold;
}

select,
input[type="text"] {
  display: block;
  width: 100%;
  height: 45px;
  padding: 10px;
  max-width: 425px;
  font-weight: bold;
  border-radius: 4px;
  margin-bottom: 15px;
  border: 1px solid #333999;
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
  background-color: #FFFFFF;
}

.btn {
  border: 0;
  width: 100%;
  height: 45px;
  display: block;
  margin: 0 auto;
  color: #FFFFFF;
  cursor: pointer;
  margin-top: 15px;
  max-width: 425px;
  font-size: 1.1rem;
  font-weight: bold;
  border-radius: 4px;
  letter-spacing: 2.2px;
  background-color: #333999;
}

.btn:hover {
  background-color: #4650f7;
}

.banner {
  color: #1E90FF;
  font-size: 3rem;
  text-align: center;
}

.amount {
  color: #1E90FF;
  font-size: 3rem;
  text-align: center;
}

#js {
  font-size: 3rem;
  margin-bottom: 0;
}

#currency {
  font-size: 2.5rem;
}

#country-code {
  font-size: 1.5rem;
}

table {
  width: 100%;
  color: #1E90FF;
  max-width: 650px;
  border-spacing: 0;
  margin: 0 auto 25px auto;
}

th {
  font-size: 1.1rem;
}

th,
td {
  padding: 25px 15px;
  text-align: center;
  border-bottom: 1px solid #333999;
}

/* Expand elements to accomodate screens of larger sizes with media queries. */
@media only screen and (min-width: 445px) {
  #menu {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
        -ms-flex-direction: row;
            flex-direction: row;
  }
  .hidden {
    display: block;
  }
  .menu-item {
    margin-right: 1px;
  }
}


@media only screen and (min-width: 576px) {
  .row {
    width: 75%;
  }
  #dollar-amount {
    font-size: 5rem;
  }
  .banner {
    font-size: 3rem;
  }
  th,
  td {
    padding: 25px 25px;
  }
}

@media only screen and (min-width: 776px) {
  #menu {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
        -ms-flex-direction: row;
            flex-direction: row;
  }
  .hidden {
    display: block;
  }
  .menu-item {
    margin-right: 1px;
  }
  #dollar-amount {
    font-size: 6rem;
  }
  .banner {
    font-size: 4rem;
  }
}

@media only screen and (min-width: 992px) {
  .banner {
    font-size: 5rem;
  }
  .column {
    margin: 0 auto;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
        -ms-flex-direction: row;
            flex-direction: row;
    -webkit-box-pack: center;
        -ms-flex-pack: center;
            justify-content: center;
  }
}

@media only screen and (min-width: 1300px) {
  .banner {
    font-size: 6rem;
  }
  .column {
    max-width: 1300px;
  }
  form {
    max-width: unset;
    min-width: 1300px;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
        -ms-flex-direction: row;
            flex-direction: row;
  }
  label:nth-child(2),
  label:nth-child(3) {
    margin-left: 1rem;
  }
}

              
            
!

JS

              
                "use strict";


const form = document.querySelector("form");
const button = document.querySelector(".btn");

// Hide table by default.
document.getElementById("hide").style.visibility = "hidden";


// Convert amount from one denomination to another.
const calculateAmount = (rate1, rate2, amount) => {
    let sum = amount * rate2;
    return `${sum.toFixed(2)}`;
};


const displayAmount = event => {
    event.preventDefault();

    // Retrieve values from the form.
    let sum = Number(document.getElementById("amount").value);
    let exchangeRate1 = document.getElementById("rate").value;
    let exchangeRate2 = document.getElementById("to").value;
    // Create variables to update elements.
    let currency = document.getElementById("currency");
    let total = document.getElementById("total");
    let code = document.getElementById("country-code");

    if (isNaN(sum)) {
        document.getElementById("hide").style.visibility = "hidden";
        currency.textContent = "";
        total.textContent = "Input not valid.";
        code.textContent = "";
        return;
    } else {
        // Show table with styling from CSS file.
        document.getElementById("hide").style.visibility = "visible";

        let rate1;
        let rate2;

        switch (exchangeRate1) {
            case "MXN":
                rate1 = 18.8495;
                break;
            case "USD":
                rate1 = 0.052923;
                break;
            case "HTG":
                rate1 = 69.8086;
                break;
            case "CUP":
                rate1 = 1.0;
                break;
            case "CAD":
                rate1 = 1.302;
                break;
            case "EUR":
                rate1 = 0.8649;
                break;
            case "XBT":
                rate1 = 0.000161245;
                break;
            case "GBP":
                rate1 = 0.760151;
                break;
            case "XOF":
                rate1 = 567.206;
                break;
            default:
                return;
        }

        switch (exchangeRate2) {
            case "MXN":
                rate2 = 18.8495;
                break;
            case "USD":
                rate2 = 0.052923;
                break;
            case "HTG":
                rate2 = 69.8086;
                break;
            case "CUP":
                rate2 = 1.0;
                break;
            case "CAD":
                rate2 = 1.302;
                break;
            case "EUR":
                rate2 = 0.8649;
                break;
            case "XBT":
                rate2 = 0.000161245;
                break;
            case "GBP":
                rate2 = 0.760151;
                break;
            case "XOF":
                rate2 = 567.206;
                break;
            default:
                return;
        }

        currency.textContent = "$";
        total.textContent = calculateAmount(rate1, rate2, sum);
        code.textContent = exchangeRate2;
    }
};


// Listen for form sumbition.
form.addEventListener("submit", displayAmount);
button.addEventListener("click", displayAmount);

              
            
!
999px

Console