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

              
                <html lang="en">
<head>
  <meta charset="utf-8">

  <title>Github Elm Demo</title>
  <meta name="description" content="Interact with the Github API using Elm.">
  <meta name="author" content="Muyiwa Olu-Ogunleye">

  <link rel="stylesheet" href="https://unpkg.com/tachyons@4.9.1/css/tachyons.min.css"/>
  <link rel="stylesheet" href="css/style.css?v=1.0"/>

  <!--[if lt IE 9]>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
  <![endif]-->
</head>

<body>
  <div class="container helvetica">
    <div class="title">
      <h1>Github Elm Demo</h1>
      <div class="subtitle">
        <h3>Interacting with the Github API using Elm.</h3>
      </div>
    </div>
    <div id="app">
      <input type="text" placeholder="Username" id="usernameTextBox">
      <button id="gatherDataButton">Gather Data</button>
      <div id="result"></div>
    </div>
  </div>
</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                let usernameTextBox = document.getElementById('usernameTextBox');

const gatherDataButton = document.getElementById('gatherDataButton');
const resultDiv = document.getElementById('result');

const updateButtonDisplay = () => {
  if (! usernameTextBox.length) {
    gatherDataButton.style.display = 'none';
  } else {
    gatherDataButton.style.display = '';
  }
};

const updateUsernameAndButtonDisplay = (event) => {
  usernameTextBox = event.target.value;
  updateButtonDisplay();
};

const pickUsername = (data) => {
  message = '';

  if(data.name) {
    message = `Username is ${data.name}`;
  } else if (data.login) {
    message = `Username unavailable, login is ${data.login}`;
  } else {
    message = 'Username and login unavailable :(';
  }

  return message;
};

const fetchUsername = (username) => {
  fetch(`https://api.github.com/users/${username}`).then(function(response) {
    if (!response.ok) {
      throw Error(response.statusText);
    }
    return response.json();
  }).then(function(data) {
    result.textContent = pickUsername(data);
  }).catch(function(err) {
    result.textContent = err.message;
  });
};

const fetchData = () => {
  fetchUsername(usernameTextBox);
};

const initialiseDOM = (_event) => {
  updateButtonDisplay();
  gatherDataButton.addEventListener("click", fetchData);
  usernameTextBox.addEventListener("input", updateUsernameAndButtonDisplay);
};


document.addEventListener("DOMContentLoaded", initialiseDOM);
              
            
!
999px

Console