css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              @import 'https://fonts.googleapis.com/css?family=Crafty+Girls'
@import 'https://fonts.googleapis.com/css?family=Annie+Use+Your+Telescope'

html 
  height: 100%
  background: linear-gradient(#919191, #F2F2F2)
  

body
  height: 95%
  font-family: 'Crafty Girls', cursive
  font-weight: bold
  text-align: center
  
button
  font-family: 'Annie Use Your Telescope', cursive
  font-weight: bold
  font-size: 150%
  
.mainBox
  width: 100%
  min-height: 100%
  margin: auto
  overflow: hidden
  
.centerBox
  width: 50%
  min-width: 250px
  height: 50%
  min-height: 300px
  margin: 2% auto 0px auto
  border: 1px solid black
  text-align: center
  overflow: hidden
  background-image: url("https://upload.wikimedia.org/wikipedia/commons/2/2e/Notecard.jpg")
  
.catBox
  width: 90%
  height: 20%
  margin: auto
  
.catItem
  display: inline-block
  position: relitive
  width: 33.4%
  margin: 5px -5px 0px 0px
  padding: 0px
  height: 50px
  text-align: center
  overflow: hidden
  
.catAdd
  width: 8%
  
.navBar
  width: 50%
  min-width: 250px
  height: 50px
  margin: 0px auto
  padding: 0px
  overflow: hidden
  
.navButton
  display: inline-block
  position: relitive
  width: 33.3%
  margin: 0px 0px 0px 0px
  padding: 0px
  height: 100%
  text-align: center
  overflow: hidden
  
.setButton
  display: block
  width: 33%
  margin: auto
  padding: 0px
  height: 60px
  text-align: center
  overflow: hidden
  
.AACButton
  display: block
  width: 33%
  margin: 20px auto
  padding: 0px
  height: 60px
  text-align: center
  overflow: hidden
  
.AECButton
  display: inline-block
  width: 33%
  margin: 20px auto
  padding: 0px
  height: 60px
  text-align: center
  overflow: hidden
  
.card
  padding-top: 14%
  
.Remove
  position: absolute
  transform: translate(4px,0px)
  color: red
  z-index: 10
  
  
            
          
!
            
              //localStorage.removeItem("flashcards");
//^ use this to delete local storage and revert to default data ^

// data format:
// data[{ catName:"", cards:[ {front:"",back:""} ] }, ... ]
// data[x].catName = Category Name
// data[x].cards[x].front
// data[x].cards[x].back
let data = [
  { 
    catName:"HTML", 
    cards: [
     { 
      front:"What is the tag for comments in HTML",
      back:"<!-- ... -->"
     },
     { 
      front:"What does this tag do? <a>",
      back:"Defines a hyperlink"
     },
     { 
      front:"What tag makes text bold?",
      back:"Use <b>text</b>"
     },
     { 
      front:"What tag resaults in larger text: <H1> or <H6>",
      back:"<H1>"
     },
     { 
      front:"What does HTML stand for?",
      back:"Hyper Text Markup Language"
     },
     { 
      front:"What is the correct HTML element for inserting a line break?",
      back:"<br>"
     },
     { 
      front:"Which character is used to indicate an end tag?",
      back:"/"
     },
     { 
      front:"What tags are used to make tables?",
      back:"<table><thead><tr><td>"
     },
     { 
      front:"How can you make an ordered list?",
      back:"<ol><li>...</li></ol>"
     },
     { 
      front:"What is the correct HTML for making a text input field?",
      back:"<input type='text'>"
     }
      
    ]
  },
  { 
    catName:"Css", 
    cards: [{ 
      front:"This is a question...",
      back:"This is the answer."
     }]
  },

  { 
    catName:"JS", 
    cards: [
     { 
      front:"This is a question...",
      back:"This is the answer."
     },
     { 
      front:"This is another question...",
      back:"This is another answer."
     }
    ]
  },
  { 
    catName:"React", 
    cards: [
     { 
      front:"This is a question...",
      back:"This is the answer."
     },
     { 
      front:"This is another question...",
      back:"This is another answer."
     }
    ]
  },
];
let localData = false; //Is the program using localStorage

//Get/Set locally stored data
if (typeof(Storage) !== "undefined") //If local storage is avalible
  {
  localData = true;
  if(localStorage.getItem("flashcards")!==null) //if there is already data in "flachcards"
    {
      data = JSON.parse(localStorage.getItem("flashcards")); //load in data
    }
  else // else save a copy of the default data into local storage
    {
      localStorage.setItem("flashcards",JSON.stringify(data));
    }
  }

// Menu/Category selection
class Categories extends React.Component
{   
  drawCats()
  {
    return data.map(function(item,ind){
      return( <button className="catItem" onClick={ this.props.handleClick.bind(this,ind)}>{ item.catName }</button> );
    },this);
  }
 
  render()
  {
    return(
      <div className="animated fadeIn">
        <h1>Categories</h1>
        <h4>Select a category</h4>
        <div className="catBox">
          { this.drawCats() }
        <button className="catItem catAdd" onClick={ this.props.addCat.bind(this,"AddCat") }>+</button>
        </div>
      </div>
    );
  }
}

// Category Menu
class CatSet extends React.Component
{ 
  constructor(props)
  {
    super(props);
    this.state = { curCat:props.ind };
  }

  render(){
    return(
      <div className="animated fadeIn"> 
        <div className="Remove"onClick={ this.props.handleClick.bind(this,"RmvCat") } >X</div>
        <h1>{ data[this.state.curCat].catName }</h1>
        <button className="setButton" onClick={ this.props.handleClick.bind(this,"Start")} >Start</button>
        <button className="setButton"  onClick={ this.props.handleClick.bind(this,"Add")}>Add Card</button>
        <button className="setButton"  onClick={ this.props.handleClick.bind(this,"Menu")}>Menu</button>
      </div>
    );
  }
}

// Add a Card
class CardEdit extends React.Component
  {    
    saveCard()
    {
      data[this.props.ind].cards.push(
      { front:$("#frontInput").val(), back:$("#backInput").val()}
      );
     if(localData) // Save updated data
       {
        localStorage.setItem("flashcards",JSON.stringify(data)); 
       }
      this.props.handleClick("CatSet"); //Go back to category menu
    }
    
    render(){
      return(
       <div className="animated fadeIn">
      <h1>Add Card</h1>
          <lable>Front:</lable><br></br>
          <textArea cols='25' rows='4' id="frontInput"></textArea>
          <br></br>
      <lable>Back:</lable><br/>
      <textArea cols='25' rows='4' id="backInput"></textArea><br />
      <button className="AECButton" onClick={ this.props.handleClick.bind(this,"CatSet")}>Cancel</button>
      <button className="AECButton" onClick={ this.saveCard.bind(this) }>Add</button>
          </div>
      );
    }   
  }

//Primary app layout

class Layout extends React.Component
{ 
  constructor()
    {
    super();
    this.state={ scr:"Cats", curCat:-1, curCard:0, front:true };
    }
  
  setCat(ind)
    {
      this.setState({ scr:"CatSet", curCat:ind });
    }
  
  //Screen Selection function  
  setClick(str)
    {
      if(str==="Menu"){ this.setState({ scr:"Cats", curCat:-1 }); }
      else if(str==="CatSet"){ this.setState({ scr:"CatSet" }); }
      else if(str==="Add"){ this.setState({ scr:"Add" }); }
      else if(str==="AddCat"){ this.setState({ scr:"AddCat" }); }
      else if(str==="Start"){ this.setState({ scr:"Cards" }); }
      else if(str==="RmvCrd"){ this.setState({ scr:"RemoveCard" }); }
      else if(str==="RmvCat"){ this.setState({ scr:"RemoveCat" }); }
    }
  
  removeCard()
    {
      if(this.state.curCat===-1){ return; }
      data[this.state.curCat].cards.splice(this.state.curCard,1);
      
      if(localData) //Save updated data set
       {
        localStorage.setItem("flashcards",JSON.stringify(data)); 
       }
      
      this.setState({ curCard:0, scr:"Cards" });
    }
  
    removeCat()
    {
      if(this.state.curCat===-1){ return; }
      data.splice(this.state.curCat,1);
      
      if(localData) //Save updated data set
       {
        localStorage.setItem("flashcards",JSON.stringify(data)); 
       }
      
      this.setState({ curCard:0, scr:"Cats", curCat:-1 });
    }
  
  addCat()
    {
      data.push( { catName:$("#catInput").val(), cards:[] } );
      if(localData) //Save updated data set
       {
        localStorage.setItem("flashcards",JSON.stringify(data)); 
       }
      this.setState({ scr:"Cats" });
    }
  
  drawCur()
    {
      if(this.state.scr==="Cats") //Menu / Categories
        {
          return ( <Categories handleClick={ this.setCat.bind(this)} addCat={ this.setClick.bind(this) }/>)
        }
      if(this.state.scr==="CatSet") // Category Menu
        {
          return( <CatSet ind={ this.state.curCat } handleClick={this.setClick.bind(this) } />);
        }
      if(this.state.scr==="Add") // Add a Card
        {
          return( <CardEdit ind={ this.state.curCat } handleClick={this.setClick.bind(this) } />);
        }
      
      if(this.state.scr==="AddCat") // Add a Category
        {
          return( 
            <div>
              <h2>Category Name:</h2>
              <textArea cols='25' rows='4' id="catInput"></textArea><br />
              <button className="AECButton" onClick={ this.setClick.bind(this,"Menu") }>Cancel</button>
              <button className="AECButton" onClick={ this.addCat.bind(this) }>Add</button>
            </div>
          );
        }
      
      if(this.state.scr==="RemoveCard") // Remove a card
        {
          return (
            <div className="card animated fadeIn">
              <h2>Delete this card?</h2>
              <button className="AECButton" onClick={ this.removeCard.bind(this) } >Ok</button>
              <button className="AECButton" onClick={ this.setState.bind(this,{ scr:"Cards" }) }>Cancel</button>
            </div>
          );
        }
      
      if(this.state.scr==="RemoveCat") // Remove a Category and all it's cards
        {
          return (
            <div className="card animated fadeIn">
              <h2>Delete this category and all of it cards?</h2>
              <button className="AECButton" onClick={ this.removeCat.bind(this) } >Ok</button>
              <button className="AECButton" onClick={ this.setState.bind(this,{ scr:"CatSet" }) }>Cancel</button>
            </div>
          );
        }
      
      if(this.state.scr==="Cards") // Draw the current card
        {
          console.log(this.state.front);
          if(this.state.front)
            {
              return(
              <div>
              <div className="Remove" onClick={ this.setState.bind(this,{ scr:"RemoveCard" }) }>X</div>
              <div className="card animated fadeIn">                  
              <h2>{ data[this.state.curCat].cards[this.state.curCard].front }</h2>
              </div></div> );
            }
          else
            {
              return(
                <div>
                  <div className="Remove" onClick={ this.setState.bind(this,{ scr:"RemoveCard" }) }>X</div>
                  <div  className="card animated fadeIn">
                    <h2>{ data[this.state.curCat].cards[this.state.curCard].back }</h2>
                  </div>
                </div>);
            }
        }
    }
  
  nextCard() //Move to the next card in the current category
    {
      let cur=this.state.curCard;
      cur++;
      if(cur>=data[this.state.curCat].cards.length){ cur=0; }
      this.setState({ curCard:cur, front:true });
    }
  
  drawNav() //Draw card's nav bar
    {
      if(this.state.scr==="Cards") //Only show nav bar when displaying cards not Menu
        {
          if(this.state.front){
            return(
              <div className="navBar animated fadeIn">
              <button className="navButton"  onClick={ this.setState.bind(this,{ scr:"Cats", curCat:-1 }) }>Menu</button>
              <button className="navButton" onClick={ this.setState.bind(this,{ front:false })}>Answer</button>
              <button className="navButton" onClick={ this.nextCard.bind(this) }>Next</button>
              </div>
            );
          }
          else
            {
              return(
              <div className="navBar animated fadeIn">
              <button className="navButton" onClick={ this.setState.bind(this,{ scr:"Cats", curCat:-1 }) }>Menu</button>
              <button className="navButton" onClick={ this.setState.bind(this,{ front:true })}>Question</button>
              <button className="navButton" onClick={ this.nextCard.bind(this) }>Next</button>
              </div>
            );
            }
        }
    }
  
  render()
    {
      return(
        <body>
        <h1 className="animated tada">Flash Cards</h1>
        <h3 className="animated zoomIn">By: Josh Sanders</h3>
        <h5 className="animated zoomIn">Made for the FCC community</h5>
        <div className="mainBox">
           <div className="centerBox animated rollIn">
             {
               this.drawCur()
             }
           </div>
          { this.drawNav() }
        </div>
       </body>
      );
    }
}

const app = document.getElementById("app");
ReactDOM.render(<Layout />,app); 
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console