cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div class = "container">
  <div class = "row">
    <div class = "col-md-6 col-sm-6 col-xs-6 col-md-offset-3 col-sm-offset-3 col-xs-offset-3">
      <h3 class = "text-center">Unit Circle Practice</h3>
     
    </div>
  </div>
  <div class = "row">
    <div class = "col-md-12 col-sm-12 col-xs-12" id = "mainContainer">
     
    </div>
  </div>
</div>
            
          
!
            
              .bordered{
border: 1px black solid;
  border-radius:5px;
padding:10px;
height: 175px;  
}

label{
  
margin-right:5px;  
  
}


            
          
!
            
              
var angles = [
{angle:"0",functionValues:[0,1,0,"undefined",1,"undefined"]},
  {angle:"\\frac{\\pi}{6}",functionValues:["\\dfrac{1}{2}","\\dfrac{\\sqrt{3}}{2}","\\dfrac{1}{\\sqrt{3}}",2,"\\dfrac{2}{\\sqrt{3}}","\\sqrt{3}"]},
  {angle:"\\frac{\\pi}{4}",functionValues:["\\dfrac{\\sqrt{2}}{2}","\\dfrac{\\sqrt{2}}{2}",1,"\\sqrt{2}","\\sqrt{2}",1]},
  {angle:"\\frac{\\pi}{3}",functionValues:["\\dfrac{\\sqrt{3}}{2}","\\dfrac{1}{2}","\\sqrt{3}","\\dfrac{2}{\\sqrt{3}}",2,"\\dfrac{1}{\\sqrt{3}}"]},
{angle:"\\dfrac{\\pi}{2}",functionValues:[1,0,"undefined",1,"undefined",0]},
  {angle:"\\frac{2 \\pi}{3}",functionValues:["\\dfrac{\\sqrt{3}}{2}","-\\dfrac{1}{2}","- \\sqrt{3}","\\dfrac{2}{\\sqrt{3}}",-2,"- \\dfrac{1}{\\sqrt{3}}"]},
  {angle:"\\frac{3 \\pi}{4}",functionValues:["\\dfrac{\\sqrt{2}}{2}","- \\dfrac{\\sqrt{2}}{2}",- 1,"\\sqrt{2}","- \\sqrt{2}",-1]},
  {angle:"\\frac{5 \\pi}{6}",functionValues:["\\dfrac{1}{2}"," - \\dfrac{\\sqrt{3}}{2}","- \\dfrac{1}{\\sqrt{3}}",2,"- \\dfrac{2}{\\sqrt{3}}","- \\sqrt{3}"]},
{angle:"\\pi",functionValues:[0,-1,0,"undefined",-1,"undefined"]},
  {angle:"\\frac{7 \\pi}{6}",functionValues:["-\\dfrac{1}{2}"," - \\dfrac{\\sqrt{3}}{2}"," \\dfrac{1}{\\sqrt{3}}",-2,"- \\dfrac{2}{\\sqrt{3}}"," \\sqrt{3}"]},
  {angle:"\\frac{5 \\pi}{4}",functionValues:["-\\dfrac{\\sqrt{2}}{2}","- \\dfrac{\\sqrt{2}}{2}", 1,"-\\sqrt{2}","- \\sqrt{2}",1]},
  {angle:"\\frac{4 \\pi}{3}",functionValues:["- \\dfrac{\\sqrt{3}}{2}","-\\dfrac{1}{2}"," \\sqrt{3}","-\\dfrac{2}{\\sqrt{3}}",-2," \\dfrac{1}{\\sqrt{3}}"]},
{angle:"\\dfrac{3 \\pi}{2}",functionValues:[-1,0,"undefined",-1,"undefined",0]},
  {angle:"\\frac{11 \\pi}{6}",functionValues:["- \\dfrac{1}{2}","\\dfrac{\\sqrt{3}}{2}","- \\dfrac{1}{\\sqrt{3}}",-2,"\\dfrac{2}{\\sqrt{3}}","-\\sqrt{3}"]},
   {angle:"\\frac{7 \\pi}{4}",functionValues:["- \\dfrac{\\sqrt{2}}{2}","\\dfrac{\\sqrt{2}}{2}",- 1,"-\\sqrt{2}","\\sqrt{2}",-1]},
   {angle:"\\frac{5 \\pi}{3}",functionValues:["-\\dfrac{\\sqrt{3}}{2}","\\dfrac{1}{2}","-\\sqrt{3}","-\\dfrac{2}{\\sqrt{3}}",2,"-\\dfrac{1}{\\sqrt{3}}"]},
  {angle:"2\\pi",functionValues:[0,1,0,"undefined",0,"undefined"]}
             
];


var numQuestions = 9;

  var newQuestions = [];
   var startValue = Math.floor(Math.random()*angles.length);
for(var i=0;i<numQuestions;i++){
  
  var newQuestion = JSON.parse(JSON.stringify(angles[(startValue+i)%angles.length]));
  
  newQuestion.showAnswers = false;
  newQuestion.index = 
  newQuestion.questionIndex = i;
 
      
     newQuestion.index = _.sample([0,1,2],1)[0];
  
  
  newQuestions.push(newQuestion);
  
}


var App = new React.createClass({
  getInitialState:function(){
    
   return {questions:this.props.questionList,showReciprocals:false}; 
    
  },
  render: function() {
  var expressionList = [];
  var showReciprocals = this.state.showReciprocals;
   var index;
    
   var currentQuestions = this.state.questions;
   
    
    var component = this;
  currentQuestions.forEach(function(f){
    
  
    
  expressionList.push( <Quiz input = {f} index = {f.index} showAnswers = {f.showAnswers} setParentState = {component.setParentState}/>)
  
})
  
    return (
      <div>
        
       <div className = "row">
         <div className = "col-md-offset-4 col-md-4 col-xs-offset-2 col-xs-4">
           <label for = "showRecip">
             Show Reciprocal Functions?   
           </label>
           <input type="checkbox" checked={this.state.showReciprocals} onChange={this.toggleReciprocalFunctions} />
           
         </div>
         <div className = "col-md-4  col-xs-4">
         <button className = "btn btn-primary" onClick = {this.getMoreQuestions} onTap = {this.getMoreQuestions}>Get More Questions</button>
        </div>
        </div>
        <hr/>
    <div>
   
     {expressionList}
    </div>
     </div>
    )
    
  },
  toggleReciprocalFunctions:function(){
    
   
   this.setState({showReciprocals:!this.state.showReciprocals}) ;
     this.getMoreQuestions();
  },
  getMoreQuestions:function(){
    var newQuestions = [];
    var component = this;
    console.log(this.state)
    var startValue = Math.floor(Math.random()*angles.length);
for(var i=0;i<numQuestions;i++){
  
  var newQuestion = JSON.parse(JSON.stringify(angles[(startValue+i)%angles.length]));
  
  newQuestion.showAnswers = false;
 
  newQuestion.questionIndex = i;
  if(component.state.showReciprocals==true){
    
    newQuestion.index = _.sample([3,4,5])
    
    
  }
    else{
      
     newQuestion.index = _.sample([0,1,2])
       
      
    }
 
  console.log(newQuestion);
  newQuestions.push(newQuestion);
  
}
        
  //console.log(newQuestions);
    
    
    this.setState({questions:newQuestions,showReciprocalFunctions:this.state.showReciprocalFunctions}) 
    
    
  },
  setParentState:function(index,object){
    
    var inputData = this.state.questions;
    var selectedData = inputData[index];
    //console.log(inputData);
    var changedProperties = Object.keys(object);
changedProperties.forEach(function(key){

selectedData[key]=object[key]

})
inputData[index]=selectedData;


    
    this.setState({questions:inputData});
    
  }

})

var Quiz = new React.createClass({
 getInitialState:function(){
   
   return {showAnswers:this.props.input.showAnswers}
   
 },
render: function(){
  
 var functionNames = ["sin \\left (","cos  \\left(","tan  \\left(","csc  \\left(","sec  \\left(","cot  \\left("]
  
 var selectedFunction = functionNames[this.props.index];
  
var expressionText = {__html: katex.renderToString( selectedFunction + this.props.input.angle + "\\right)", { displayMode: true })};
  
 if(this.props.input.showAnswers===true){
  var answer= this.props.input.functionValues[this.props.index];
var answerText = {__html: katex.renderToString("Answer:"+answer+"",{ displayMode: true })}
}
  else{
    
 var answerText = {__html:""}

    
  }
  
return (

<div className = "">
  
  
    <div className = "col-md-4 col-xs-4 bordered">
     <div className = "row">
      <div className = "col-md-12 col-xs-12" ref = "katex" dangerouslySetInnerHTML = {expressionText}>
        
       </div>
   
    </div>
      <div className = "row">
      <div className = "col-md-12 col-xs-12 text-center">
        <button className = "btn btn-primary" onClick = {this.showAnswers} onTap = {this.showAnswers}>Show Answer</button>
        </div>
      </div>
      
      <div className = "row">
      <div className = "col-md-12 col-xs-12" ref = "katexAnswer" dangerouslySetInnerHTML={answerText}>
       
        
       </div>
    
    </div>
  </div>

  </div>

)

    },
  showAnswers:function(){
    //console.log(this.props);
   this.props.setParentState(this.props.input.questionIndex,{showAnswers:true}) 
    
  }
})

ReactDOM.render(<App questionList = {newQuestions} />, document.getElementById("mainContainer"));
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console