Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!-- Maths Homework Generator by 101Computing.net - www.101computing.net/maths-homework-generator -->
<div class="no-print"> 
Type of equations: <select id=typeOfEquations>
  <option value=1>Addition, 2 operands</option>
  <option value=2>Subtraction, 2 operands</option>
  <option value=3>Multiplication, 2 operands</option>
  <option value=4>Division, 2 operands</option>
  <option value=5 selected>+ - x / , 2 operands</option>
</select><br/>
Number of digits per operand:<select id=numberOfDigits>
  <option value=1>1 digit</option>
  <option value=2>2 digits</option>
 <option value=3>3 digits</option>
  <option value=4>4 digits</option>
  <option value=5>5 digits</option>
  <option value=6>6 digits</option> 
</select><br/>  
Number of equation: <select id=numberOfEquations>
  <option value=5>5 equations</option>
  <option value=10 selected>10 equations</option>
  <option value=15>15 equations</option>
  <option value=20>20 equations</option>
  </select></br>

<input type=button value="Create Worksheet" onclick="JavaScript: generateEquations();">
<input type=button value="Print Worksheet" onclick="JavaScrit:window.print();">
</div>
<div id=title></div>
<div id=worksheet>
</div> 
  
              
            
!

CSS

              
                #worksheet { 
}
.no-print {
  background-color: #CCCCCC;
  font-family: trebuchet ms;
  line-height: 1.5;
}
@media print
{    
    .no-print, .no-print *
    {
        display: none !important;
    }
}

#title {
  font-size: 20pt;
  font-family: Times New Roman;
  padding-top: 15px;
  padding-bottom: 15px;
  text-align: center;
  border-bottom: #000000 solid 1px;
  margin-bottom: 10px;
}


.equation {
  font-size: 20pt;
  font-family: Times New Roman;
  padding-top: 15px;
  padding-bottom: 15px;
  border-bottom: #CCCCCC dashed 1px;
}


.number {
  color: red;
}
  
              
            
!

JS

              
                function getDropDownListValue(name) {
  var list = document.getElementById(name);
  return list.options[list.selectedIndex].value;
}

function generateEquations(){
  var typeOfEquations = getDropDownListValue("typeOfEquations");
  var numberOfEquations = getDropDownListValue("numberOfEquations");
  var numberOfDigits = getDropDownListValue("numberOfDigits");

  var operand1, operand2, operator, equation, operators;
  switch(typeOfEquations) {
    case '1':
        operators=['+'];
        document.getElementById('title').innerHTML='Additions';
        break;
    case '2':
        operators=['-'];
        document.getElementById('title').innerHTML='Subtractions';  
        break;
    case '3':
        document.getElementById('title').innerHTML='Multiplications';
        operators=['x'];
        break;
    case '4':
        document.getElementById('title').innerHTML='Divisions';
        operators=['/'];
        break;      
    case '5':
        document.getElementById('title').innerHTML='Arithmetic Calculations';
        operators=['+','-','x','/']
        break;
   }

  document.getElementById('worksheet').innerHTML = '';
  
  for (i = 1; i <= parseInt(numberOfEquations); i++) {
    operand1 = Math.floor((Math.random() * (Math.pow(10,numberOfDigits)+1)));
    operand2 = Math.floor((Math.random() * (Math.pow(10,numberOfDigits)+1)));
    operator = operators[Math.floor(Math.random() * operators.length)];

    equation = String(operand1) + ' ' + operator + ' ' + String(operand2) + ' =';

    document.getElementById('worksheet').innerHTML =  document.getElementById('worksheet').innerHTML + '<div class=equation><span class=number>' +String(i) + ')&nbsp;&nbsp;&nbsp;</span>' + equation + '</div>';
  }
}


              
            
!
999px

Console