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.


<h1>Week running table</h1>

<button onclick="calc()">Do It!</button>

<div id="days">
    <h2>Day 1</h2>
    <input type="text" placeholder="Description" id="day1"><input type="number" placeholder="Distance" value=0 id="day1Km">

    <h2>Day 2</h2>
    <input type="text" placeholder="Description" id="day2"><input type="number" placeholder="distance2" value=0 id="day2Km">

    <h2>Day 3</h2>
    <input type="text" placeholder="Description" id="day3"><input type="number" value=0 placeholder="distance" id="day3Km">

    <h2>Day 4</h2>
    <input type="text" placeholder="Description" id="day4"><input type="number" value=0 placeholder="Distance" id="day4Km">

    <h2>Day 5</h2>
    <input type="text" placeholder="Description" id="day5"><input type="number" value=0 placeholder="Distance" id="day5Km">

    <h2>Day 6</h2>
    <input type="text" placeholder="Description" id="day6"><input type="number" value=0 placeholder="Distance" id="day6Km">

    <h2>Day 7</h2>
    <input type="text" placeholder="Description" id="day7"><input type="number" value=0 placeholder="Distance" id="day7Km">

<p id="result">Please fill-in form and click on the button</p>

<p id="avgResult"></p>

<section id="chart">
  <h2>Chart output</h2>
  <p id="p1">Day 1</p> <div id="c1"></div>
  <p id="p2">Day 2</p> <div id="c2"></div>
  <p id="p3">Day 3</p> <div id="c3"></div>
   <p id="p4">Day 4</p><div id="c4"></div>
  <p id="p5">Day 5</p> <div id="c5"></div>
  <p id="p6">Day 6</p> <div id="c6"></div>
  <p id="p7">Day 7</p> <div id="c7"></div>
  <p>Week average chart</p>
  <div id="avgC"></div>
              * {
  font-family: Arial;
  margin: 0px;
  padding: 0;

h1 {
  padding: 16px;
  background: #3498db;
  color: white;

input {
  margin: 10px;

input {
  padding: 10px;

#days {
  display: flex;

button {
  padding: 10px;
  background: white;
  border: none;
  color: #3498db;
  font-size: 24px;

#chart > div {
  display: flex;
  margin: 10px;
  background: #3498db;
  width: 20px;
  height: 20px;

margin: 10px;
function calc() {

  //define variables
  var d1km = document.getElementById("day1Km").value;
  var d2km = document.getElementById("day2Km").value;
  var d3km = document.getElementById("day3Km").value;
  var d4km = document.getElementById("day4Km").value;
  var d5km = document.getElementById("day5Km").value;
  var d6km = document.getElementById("day6Km").value;
  var d7km = document.getElementById("day7Km").value;
  var total = 0;
  var result = document.getElementById("result");
  var avg;
  var avgResult = document.getElementById("avgResult");

  //chart variables
  var c1 = document.getElementById("c1");
  var c2 = document.getElementById("c2");
  var c3 = document.getElementById("c3");
  var c4 = document.getElementById("c4");
  var c5 = document.getElementById("c5");
  var c6 = document.getElementById("c6");
  var c7 = document.getElementById("c7");
var avgC= document.getElementById("avgC");
  //chart legend variables
  var p1 = document.getElementById("p1");
  var p2 = document.getElementById("p2");
  var p3 = document.getElementById("p3");
  var p4 = document.getElementById("p4");
  var p5 = document.getElementById("p5");
  var p6 = document.getElementById("p6");
  var p7 = document.getElementById("p7");

  //input variables
  var legend1 = document.getElementById("day1").value;
  var legend2 = document.getElementById("day2").value;
  var legend3 = document.getElementById("day3").value;
  var legend4 = document.getElementById("day4").value;
  var legend5 = document.getElementById("day5").value;
  var legend6 = document.getElementById("day6").value;
  var legend7 = document.getElementById("day7").value;

 //assign input field text to legend
  //size chart columns by values of fields
  c1.style.width = parseFloat(d1km) + "%";
  c2.style.width = parseFloat(d2km) + "%";
  c3.style.width = parseFloat(d3km) + "%";
  c4.style.width = parseFloat(d4km) + "%";
  c5.style.width = parseFloat(d5km) + "%";
  c6.style.width = parseFloat(d6km) + "%";
  c7.style.width = parseFloat(d7km) + "%";

  //sum of km
  total = parseFloat(d1km) + parseFloat(d2km) + parseFloat(d3km) + parseFloat(d4km) + parseFloat(d5km) + parseFloat(d6km) + parseFloat(d7km);

  //week average
  avg = Number(total / 7);

  //show results
  result.innerHTML = "You ran " + "<b>" + total + "</b>" + " km this week.";
  avgResult.innerHTML = "You ran " + "<b>" + avg + "</b>" + " km on average day.";
🕑 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.