Pen Settings



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


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


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.


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.


                <h1>Area Under f(x)=x^2</h1>
Beginning x value: <input type="text" value="0" id="beginning" /><br />
Ending x value: <input type="text" value="10" id="ending" /><br />
Number of slices: <input type="text" value="20" id="slices" /><br />
<input type="button" value="Calculate" id="calculate" /><br />
Result: <input type="text" value="" id="result" />


                body {
  margin: 20px;
  background-color: #58b1d8;
  color: #FFFFFF;
  font-family: sans-serif;

h1 {
  font-weight: normal;
  padding-bottom: 10px;
  border-bottom: 2px solid #FFFFFF;

input[type="text"] {
  border: 0;
  padding: 5px;

#calculate {
  border: 0;
  padding: 10px;
  margin: 10px;
  background-color: #FFFFFF;
  color: #000000;

#calculate:hover {


                //The function we will find the area under
var f = function(x) {
  //This is how we do powers in Javascript: Math.pow(base, exponent)
  return Math.pow(x, 2);

//When the calculate button has been clicked
var calculateArea = function() {
  var min = parseFloat(document.getElementById("beginning").value);
  var max = parseFloat(document.getElementById("ending").value);
  var slices = parseFloat(document.getElementById("slices").value);
  var sliceWidth = (max-min)/slices;
  var area = 0;
  for (var i = 0; i < slices; i++) {
    area += sliceWidth * f(min + sliceWidth*i);
  document.getElementById("result").value = area;

//When the page has loaded
window.onload = function() {
  document.getElementById("calculate").onclick = calculateArea;