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 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

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

              
                <table>
  <tr>
    <th>Item</th>
    <th>Team</th>
    <th>Hours</th>
  </tr>
  <tr>
    <td>Designing the shop front</td>
    <td>Tigers</td>
    <td>200</td>
  </tr>
  <tr>
    <td>Developing the MVP</td>
    <td>Panthers</td>
    <td>500<br></td>
  </tr>
  <tr>
    <td>Feature request #999</td>
    <td>Panthers</td>
    <td>450</td>
  </tr>
  <tr>
    <td>Creating  sales pitches</td>
    <td>Lions</td>
    <td>1100<br></td>
  </tr>
  <tr>
    <td>Designing the Christmas banner</td>
    <td>Tigers<br></td>
    <td>130</td>
  </tr>
</table>
<br>

<a title="Bookmarklet calculating the grouped costs" href="javascript:(function()%7Balert(JSON.stringify(Array.from(document.querySelectorAll(%22tr%3Anth-of-type(n%2B2)%22)).reduce((acc%2C%20row)%20%3D%3E%20%7Bconst%20team%20%3D%20row.children%5B1%5D.textContent%3Bconst%20hours%20%3D%20%2Brow.children%5B2%5D.textContent%3Breturn%20%7B%20...acc%2C%20%5Bteam%5D%3A%20(acc%5Bteam%5D%20%7C%7C%200)%20%2B%20hours%20%7D%3B%7D%2C%7B%7D)))%7D)()">Calculate the grouped costs by clicking this bookmarklet!</a> (demo 1)

<br><br>

You can also try the <a href="javascript:(function()%7Blet%20groupedHourCounts%20%3D%20Array.from(document.querySelectorAll(%22tr%3Anth-of-type(n%2B2)%22)).reduce((acc%2C%20row)%20%3D%3E%20%7Bconst%20team%20%3D%20row.children%5B1%5D.textContent%3Bconst%20hours%20%3D%20%2Brow.children%5B2%5D.textContent%3Breturn%20%7B%20...acc%2C%20%5Bteam%5D%3A%20(acc%5Bteam%5D%20%7C%7C%200)%20%2B%20hours%20%7D%3B%7D%2C%20%7B%7D)%3Blet%20listItems%20%3D%20Object.keys(groupedHourCounts).map(key%20%3D%3E%20%60%3Cli%3E%24%7Bkey%7D%3A%20%24%7BgroupedHourCounts%5Bkey%5D%7D%3C%2Fli%3E%60).join(%22%5Cn%22)%3Blet%20doc%20%3D%20%60%3Chtml%3E%3Chead%3E%3Ctitle%3EGrouped%20counts%3C%2Ftitle%3E%3C%2Fhead%3E%3Cbody%3E%3Ch1%3EGrouped%20cost%20counts%3C%2Fh1%3E%3Cul%3E%24%7BlistItems%7D%3C%2Ful%3E%3Cinput%20type%3D%22button%22%20onclick%3D%22window.history.back()%3B%22%20value%3D%22Back%20to%20the%20example%22%3E%3C%2Fbody%3E%3C%2Fhtml%3E%60%3Bconsole.log(doc)%3Breturn%20doc%7D)()">bookmarklet document</a> (demo 2)

<p>
I used <a href="https://mrcoles.com/bookmarklet/">this bookmarklet encoder</a> to encode the JavaScript into a URI string that is allowed in the HTML attribute <code>href</code>. Doing this manually becomes a hassle!
</p>

              
            
!

CSS

              
                
              
            
!

JS

              
                // all JavaScript here was converted to a URI and put into a link
// Use for example this encoder https://mrcoles.com/bookmarklet/

// DEMO 1 code
// extract the information from the table, group it in an object, and alert() the result

alert(
  JSON.stringify(
    Array.from(document.querySelectorAll("tr:nth-of-type(n+2)")).reduce(
      (acc, row) => {
        const team = row.children[1].textContent;
        const hours = +row.children[2].textContent;
        return { ...acc, [team]: (acc[team] || 0) + hours };
      },
      {}
    )
  )
);

// DEMO 2 code: present using a bookmarklet document
//
// This extracts the information from the table, groups it, and returns it as a HTML document in a string.
// The return value will be shown in a special javacript: link HTML document by the browser when clicked.
let groupedHourCounts = Array.from(
  document.querySelectorAll("tr:nth-of-type(n+2)")
).reduce((acc, row) => {
  const team = row.children[1].textContent;
  const hours = +row.children[2].textContent;
  return { ...acc, [team]: (acc[team] || 0) + hours };
}, {});

let listItems = Object.keys(groupedHourCounts)
  .map(key => `<li>${key}: ${groupedHourCounts[key]}</li>`)
  .join("\n");
let doc = `
<html>
  <head>
    <title>Grouped counts</title>
  </head>
  <body>
    <h1>Grouped cost counts</h1>
    <ul>
      ${listItems}
    </ul>
    <input type="button" onclick="window.history.back();" value="Back to the example">
  </body>
</html>
`;
console.log(doc);
return doc;

// NOTE: adding target="_blank" to your link makes the js execute in the wrong context somehow. You can't use it.

// Presentation option 3: you could also inject the answer back into the DOM.
// Take this as an exercise :)
              
            
!
999px

Console