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

              
                <h1>-From Scratch- Challenges</h1>
<h2>Palindrome (JS) + FizzBuzz (JS) + Pomodoro Clock (JS) + GistBox (React: 16.2.0)</h2>
<div id="root"></div>
<br/>
<hr/>
<footer>
  <ul>
    <li><b>Palindrome</b> + <b>FizzBuzz</b> + <b>Pomodoro Clock</b> &rarr; Console Log</li>
    <li><b>GistBox - React: 4 components</b> &rarr; Form Input / Div Output
      <ol>
        <li>&lt;GistBox&gt; is HOC; It accepts form input and generates a prop (object) output</li>
        <li>&lt;GistForm&gt; should submit input username to parent &lt;GistBox&gt; prop (method)</li>
        <li>&lt;GistList&gt; should iterate over 1 provided prop (object)</li>
        <li>&lt;Gist> should simply output 1 provided prop (object)</li>
        <li>ReactDOM to render results</li>
      </ol>
    </li>
    <li>Mark time => Start. Run. Fix issues (dev tools) => Mark time.</li>
  </ul>
  <p>
    Note: This is my practice 'GistBox' Pen (my time entries are commented out at the bottom of the HTML code). The enhanced version of my 'React From Scratch' GistBox quickplate is at: <a href="https://codepen.io/KeithDC/pen/dzdqaV">https://codepen.io/KeithDC/pen/dzdqaV</a>
  </p>
  <div id="last-time">
    My last time entry <i>(from the hidden comments in the HTML code)</i>
    <pre>// 2018-08-12 (Sun) // All 4: 32 min (GistBox: 17 min)
       // Started #1: 12:39 PM
       // Finished #4: 1:11 PM</pre>
  </div>
</footer>
<!--
<history class="hidden">

// var celsius = 0, fahrenheit = (celsius * 9/5) + 32;

// 2017-10-22 | 4:12 PM / 4:30 PM == 18 min (~2 min of distractions)
// 2017-10-23 | 7:06 PM / 7:24 PM / 7:29 PM (3 fixes) == 23 min
// 2017-10-26 | 11:55 AM / 12:12 PM / 12:15 PM (3 fixes) == 20 min
    // [ReactDOM...] (doh!); this.[state.]gistList; [this.]updateGistList() (x2)
// 2017-10-27 | 9:05 PM / 9:20 PM / 9:23 PM (2 fixes) == 18 min
    // [</label>] (1 min); [<buttom>] (2 min)
// 2017-10-29 | 3:22 PM / 3:36 PM / 3:39 PM (3 fixes) == 17 min
    // [updateGistList(e) {]; [login: {username}](var; no braces; over-thought); [listitem]

// 2017-11-04 | 1:21 PM / 1:38 PM / 1:49 PM (2 fixes) == 28 min
    // [this.]updateGistList(thisGist); (1 min)
    // const { username, url } = this.props[.gist], (10 min to find this)
// 2017-11-05 | 4:17 PM / 4:34 PM / 4:38 PM (1 fix) == 21 min
    // First time writing out full async/await fetch from memory.
    // missed [return()] around <div> ^-> class GistList ^-> render() ^-> [return ()]

// 2017-11-19 | 8:18 PM / 8:36 PM / 8:38 PM (3 fixes) == 20 min
    // 2 syntax; 1 [ReactDOM...] (doh!!)
    // autoFocus=[true] ^-> "true" (Props: Either strings or {React} references)
    // this.props.gistList.map( [)] ^-> Missed ending )
    // Somehow I got the fetch/async/await all right.

// 2017-12-18 | 11:31 PM / 11:50 PM / 11:57 PM (>=3 fixes) === 26 min
    // Fetch fubar (didn't even do async/await)
    // Gist object ^-> Missed owner: [id]?? ^-> owner: [login]!!
    // A little disappointed in the fetch, but otherwise felt pretty good (although glad I did a small warm-up).
// 2017-12-19 | 11:03 AM / 11:24 AM (0 fixes) === 21 min
// 2017-12-20 | 07:10 PM / 07:24 PM / 07:25 PM (1 fix) === 15 min
    // Typo: thisGist = dat[0]; ^-> 'dat' ==> 'data'
// 2017-12-22 | 10:21 PM / 10:36 PM / 10:37 PM (1 fix) === 16 min
    // Type: onChage={this.formChange} ^-> 'onChage' ==> 'onChange'

// 2017-12-28 | 10:32 PM / 10:45 PM / 10:47 PM (1 adjustment) === 15 min
    // <td className="listitem"> ==> <td><span className="listitem">

// 2018-01-10 | 06:23 PM / 6:40 PM / 11:08 PM (2 fixes; 1 major) === 45 min
    // Ate dinner; found the culprit! A missing `/>` on `<GistList />`
    // And a missing `await` on `response.json()`
// 2018-01-11 | 05:26 PM / 05:39 PM (0 fixes) === 13 min
// 2018-01-19 | 08:25 PM / 08:39 PM / 08:40 PM (1 fix) === 15 min
    // Forgot the 2 `await's`.

// 2018-01-31 - 2:48 PM / 3:01 PM / 3:18 PM === 30 min (4 fixes)
    // missed </span>
    // forgot ReactDOM.render
    // it's `.then`, not `.next` - I've no idea where .next came from! Generators?
    // missed setting GistBox methods as arrow functions (d'oh!))
// 2018-02-01 - 1:44 AM / 2:06 AM / 2:08 AM === 24 min (1 fix)
    // Gist owner has a `login` not `login_id`
    // Talked (mumbled) myself through the entire process)
// 2018-02-04
    // GistBox = 2:10 PM / 2:22 PM / 2:23 PM === 13 min (1 fix)
        // forgot: e.preventDefault();

    // Did all 4 === 31 min // Started: 1:52 PM | Finished: 2:23 PM
// 2018-02-07
    // GistBox = 2:17 PM / 2:29 PM / 2:30 PM === 13 min (1 fix)
        // missed ending `/>` in `<Gist ... />`

    // Did all 4 === 25 min // Started: 2:05 PM | Finished: 2:30 PM

// 2018-02-17
    // GistBox = 11:40 AM / 11:52 AM / 11:54 AM === 14 min (1 fix)
        // Misspelling: class GistLst -> class GistList

    // Did all 4 === 25 min // Started: 11:29 AM | Finished: 11:54 AM

// 2018-02-28 - GistBox = 4:19 PM / 4:30 PM / 4:50 PM === 29 min (3 fixes)
    // Missed: ` />` on end of `<GistList`
    // Missed: `.login` on end of `const username = newGist.owner.login,`
    // Missed: left parens after `.map(gist, idx)` with `this.props.gistList.map( (gist, idx) =>`

    // Did all 4 === 52 min // Started: 3:58 PM | Finished: 4:50 PM

       * 2018-02-28 @ 3:58 PM / 4:05 PM [Palindrome] (1 fix; missed `, ''` in replace).
       * 2018-02-28 @ 4:12 PM / 4:16 PM [FizzBuzz] (1 fix; `<` instead of `<=`)
       * 2018-02-28 @ 4:05 PM / 4:11 PM [Pomodoro] (1 fix; copy/paste; forgot to change `run5()` to `run25()`)
       * 2018-02-28 @ 4:19 PM / 4:31 PM / 4:50 PM (3 fixes; noted above)

// 2018-03-07 - GistBox = 3:50 PM / 4:04 PM === 14 min (0 fixes)

    // Did all 4 === 29 min // Started: 3:37 PM | Finished: 4:06 PM

       * 2018-03-07 @ 3:37 PM / 3:40 PM
       * 2018-03-07 @ 3:40 PM / 3:43 PM
       * 2018-03-07 @ 3:43 PM / 3:50 PM (+2; after-the-fact tweaks to console logs)
       * 2018-03-07 @ 3:50 PM | 4:04 PM

// 2018-03-17 - GistBox = 3:04 PM / 3:20 PM / 3:39 PM === 35 min (2 fixes)
    // Missed `[0]` on `data[0]`
    // Misspelled `usesrname` in GistForm's `onSubmit`

    // Did all 4 === 47 min // Started: 2:52 PM | Finished: 3:39 PM

      * 2018-03-17 @ 2:52 PM / 2:55 PM (1 fix; `/g`)
      * 2018-03-17 @ 3:01 PM / 3:04 PM
      * 2018-03-17 @ 2:55 PM / 3:01 PM (oops, did before Fizz.)
      * 2018-03-17 @ 3:04 PM / 3:20 PM / 3:39 PM = 35 min (2 fixes; noted above)

// 2018-03-26 - GistBox = 6:44 PM / 6:59 PM / 7:10 PM === 26 min (1 fix)
    // Missed `gistList =` (I always forget `.concat()` returns a new array.)

    // Did all 4 === 40 min // Started: 6:30 PM | Finished: 7:10 PM

      * 2018-03-26 @6:30 PM : Palindrome
      * 2018-03-26 @6:32 PM : FizzBuzz
      * 2018-03-26 @6:37 PM : Pomodoro
      * 2018-03-26 @6:44 PM / 6:59 PM / 7:10 PM (1 fix)

// 2018-04-02 - GistBox = 6:26 PM / 6:41 PM / 6:55 PM === 29 min (3 fixes)
    // Missed `/>` end of `<GistList`
    // `.then` missed `=>` on arrow function
    // Capitalization misspell on `gistlist` vs `gistList`

      * 2018-04-02 @6:12 PM / @6:15 PM : 1 fix; missed `g` for regex global
      * 2018-04-02 @6:15 PM / @6:18 PM
      * 2018-04-02 @6:19 PM / @6:26 PM : 1 fix; missed delays on setTimeout
      * 2018-04-02 @6:26 PM / @6:41 PM / @6:55 PM : 29 min (3 fixes)

// 2018-04-14 - GistBox = 2:58 PM / 3:15 PM === 17 min (2 fixes)
    // Missed: `</label>`
    // Capitalization misspell on `placeholder` vs `placeHolder`

      * 2018-04-14 @2:41 PM / 2:45 PM
      * 2018-04-14 @2:46 PM / 2:49 PM
      * 2018-04-14 @2:49 PM / 2:58 PM
      * 2018-04-14 @2:58 PM / 3:15 PM : 17 min (2 fixes)

// 2018-05-06 - GistBox = 9:31 PM / 9:47 PM === 16 min (0 fixes)
      * 2018-05-06 @9:16 PM / 9:18 PM
      * 2018-05-06 @9:18 PM / 9:24 PM
      * 2018-05-06 @9:25 PM / 9:31 PM
      * 2018-05-06 @9:31 PM / 9:47 PM : 16 min

// 2018-05-29 - GistBox = 2:32 PM / 3:04 PM === 32 min (~2 fixes (fixed enroute))
      * 2018-05-29 - @2:14 PM / @2:16 PM
      * 2018-05-29 - @2:16 PM / @2:21 PM
      * 2018-05-29 - @2:21 PM / @2:31 PM : 2 fixes; Didn't put setTimeout inside () => {}, initial console.log())
      * 2018-05-29 - @2:32 PM / @3:04 PM : 32 min (2 fixes)
        // Not 'async nameOfFunc function(){}'
        // forgot [0] on data[0]

// 2018-06-17 - GistBox = 4:41 PM / 4:57 PM === 16 min (2 fixes)
      * 2018-06-17 @4:23 PM - 
      * 2018-06-17 @4:28 PM - 
      * 2018-06-17 @4:35 PM - 
      * 2018-06-17 @4:41 PM - @4:57 PM (2 fixes)
        // Forgot prop: gistList={this.state.gistList}
        // Bad capital: GistList: []

// 2018-07-08 - GistBox = 11:51 AM / 12:11 PM === 20 min (2 fixes)
      * 2018-07-08 11:34 AM - 11:38 AM
      * 2018-07-08 11:44 AM - 11:50 AM
      * 2018-07-08 11:38 AM - 11:44 AM // Accidentally did before fizzBuzz (2nd/3rd time...?)
      * 2018-07-08 11:51 AM - 12:11 PM
        // Forgot to wrap <GistForm/> and <GistList/> in <div> or fragment.
        // Added semicolon after `document.getElementById('root');` param.

// 2018-08-12 - GistBox = 12:54 PM / 1:11 PM === 17 min (1 fix)
      * 2018-08-12 @12:39 PM - 
      * 2018-08-12 @12:43 PM - 
      * 2018-08-12 @12:46 PM - 
      * 2018-08-12 @12:54 PM - @1:11 PM ==> 17 minutes
        // Missed end parens ) on the fetch `.catch()`

</history>
-->
              
            
!

CSS

              
                body {
  font-family: arial;
  font-size: 16px;
}
.listitem {
  display: inline-block;
  font-size: 12px;
  margin-top: 0.35rem;
}
#last-time {
  background-color: lightyellow;
  margin: 0.5rem 0 0;
  overflow: auto;
}
footer {
  background-color: #ffffff;
  border-top: 1px solid gray;
  box-shadow: inset 1px 2px gray;
  font-size: 11px;
  margin: 0.5em auto;
  overflow-x: auto;
  padding: 0 0.5em;
/*   position: fixed; */
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1;
  width: 95%;
}
ul,
ol {
  line-height: 1.5;
  margin: 0;
  padding: 0;
}
ul {
  list-style: none;
  margin: 0.5rem 0 0 0.2rem;
}
ul li {
  margin: 0;
  padding: 0;
}
ul > li:before {
  content: '- ';
}
ol li {
  margin: 0 0 0 20px;
  padding: 0;
}
cite {
  display: block;
  font-size: 10px;
  margin-bottom: .2rem;
}
.hide,
.hidden {
  display: none;
}
              
            
!

JS

              
                // From Scratch:

   // Do all four coding tasks from scratch
   // (just CodePen, Dev Tools, and your memory.)

   // palindrome
   // fizzbuzz
   // pomodoro clock
   // gistbox

;console.clear();

console.log('Ready for some user input!');

/**
  * palindrome
  * - A word or sentence that's spelled the same way both forward and backward;
  * - Return true if the given string is a palindrome. Otherwise, return false.
  * - Note: Only test for letters and numbers.
  * 2018-08-12 @12:39 PM - 
  */

// Begin

const testStr = "Tree-656-eerT";

function isPal(thisStr) {
  
  const strArr = thisStr.split(''),
        leftA = strArr.slice(0,Math.floor(strArr.length/2)),
        rightA = strArr.slice(Math.ceil(strArr.length/2));
  return leftA.join() === rightA.reverse().join();

  // const strArr = thisStr.split(''),
  //       arrLoop = Math.floor(strArr.length/2);
  // let returnIt = true;
  // for (let i = 0; i < arrLoop; i++) {
  //   if (strArr[i] !== strArr[strArr.length-1-i]) {
  //     returnIt = false;
  //   }
  // }
  // return returnIt === true ? true : false;
}
console.log("Is a Pal: ", isPal(testStr));
// 12:07 AM
/**
  * fizzbuzz
  * - Multiples of 3 = fizz
  * - Multiples of 5 = buzz
  * - Note: Minimum `countTo` = 15
  * 2018-08-12 @12:43 PM - 
  */

// Begin

const printArr = [];

let countTo = 15;

for (let i = 1; i <= countTo; i++) {
  if (i % 15 === 0) {
    printArr.push('fizzbuzz');
  } else if (i % 5 === 0) {
    printArr.push('buzz');
  } else if (i % 3 === 0) {
    printArr.push('fizz');
  } else {
    printArr.push(i);
  }
}
console.log('FIZZ: ', printArr);

/**
  * pomodoro clock
  * - 25/5 minute pomodoro.
  * - Note: Minimum `runTo` = 5
  * - Tip: Use 2/5 "second" ratio for testing.
  * 2018-08-12 @12:46 PM - 
  */

// Begin

let pBreak = 1, // Seconds
    pWork = 3, // Seconds
    pLoops = 3,   // Min loops
    pCount = 0,
    pRunWork = () => {
      console.log('Let\'s get to work!', pCount);
      setTimeout(() => { 
        pCount++; 
        if (pCount < pLoops) pRunBreak(); 
        else console.log('Good Job!!!');
      }, pWork * 1000);
    },
    pRunBreak = () => {
      console.log('Let\'s take a break!!', pCount);
      setTimeout(() => { pRunWork(); }, pBreak * 1000);
    };
pRunWork();

/**
  * gistbox
  * - My Real GistBox (with directions) is at:
  * - https://codepen.io/KeithDC/pen/dzdqaV
  * 2018-08-12 @12:54 PM - @1:11 PM ==> 17 minutes
  */

// daily-project: GetGist

    // This is a 'from scratch' project I try to write out when possible
    // Note: I don't write out the 'dangerouslySetInnerHTML' part.

    // My new updated version is at: https://codepen.io/KeithDC/pen/dzdqaV
    // Although I would focus on this one first (there's no TypeScript).

    // This project was inspired by Laracasts (early 2017):
    // https://laracasts.com/series/do-you-react/episodes/7

    // Your Task: Write out everything below from memory:
    // --------------------------------------------------

// GistBox
    // GistForm
    // GistList
        // Gist

;console.clear();

const noGistMsg = 'This GitHub user has no Gists.';

class GistBox extends React.Component {

    state = {
        gistList: []
    };

    getGist = (usernameInput) => {
        const url = `https://api.github.com/users/${usernameInput}/gists`;

        async function fetchAsync(getUrl) {
            let response = await fetch(getUrl, { method: 'GET' });
            let data = await response.json();
            return data;
        };

        fetchAsync(url).then( data => {
            var thisGist = {};

            if (data.length > 0) {
                thisGist = data[0];
            } else {
                thisGist = {
                    owner: {
                        login: usernameInput
                    },
                    html_url: noGistMsg
                };
            }
            this.updateGistList(thisGist);
        })
    }
    updateGistList = (gist) => {
        let username = gist.owner.login,
            url = gist.html_url,
            gistList = this.state.gistList;
        gistList = gistList.concat({ username, url });
        this.setState({ gistList });
    }
    render() {
        return (
            <div>
                <GistForm submitUser={this.getGist} />
                <GistList gistList={this.state.gistList} />
                {this.props.children}
            </div>
        );
    }
}
class GistForm extends React.Component {

    state = {
        username: ''
    };

    formChange = (e) => {
        this.setState({ username: e.target.value });
    }
    formSubmit = (e) => {
        e.preventDefault();
        if (this.state.username.length > 0) {
            this.props.submitUser(this.state.username);
            this.setState({ username: '' });
        }
    }
    render() {
        return (
            <div>
                <form onSubmit={this.formSubmit}>
                    <label>Enter a GitHub username for a link to their last Gist:<br/>
                        <input 
                            type="text" 
                            onChange={this.formChange} 
                            value={this.state.username} 
                            placeholder="kdcinfo"
                            autoFocus={true}
                        />
                    </label>
                    <button>Get Gist</button>
                </form>
            </div>
        );
    }
}
class GistList extends React.Component {
    render() {
        const { gistList } = this.props;
        return (
            <table>
                <tbody>
                    { gistList.map( (gist, idx) => <Gist key={idx} gist={gist} /> ) }
                </tbody>
            </table>
        );
    }
}
class Gist extends React.Component {
    render() {
        const { username, url } = this.props.gist,
              userurl = (url === noGistMsg) ? noGistMsg : <a href={url} target="kdcNewWin">{url}</a>;
        return (
            <tr className="listitem">
                <td>{username}</td>
                <td>{userurl}</td>
            </tr>
        );
    }
}
ReactDOM.render(
    <GistBox/>,
    root
)

              
            
!
999px

Console