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

              
                <!-- Demo Interface for a Fitness Tracker - Full Project Coming Soon -->

<div class="modal">
  <div class="wrapper">
    <div class="modal-head">
      <header>
        <h1>Workout</h1>
      </header>
    </div>
    <div class="body">
      <p>Enter your workout.</p>
      <div class="form-wrapper">
        <form>
          <h2 id="prompt">Add First Exercise...</h2>
          <div class="add-entry">
            <button class="btn-add-exercise">+ Add Exercise</button>
          </div>
        </form>
      </div>
      <div class="submit">
        <button class="btn-submit">Log Workout</button>
      </div>
    </div>
  </div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Karla:wght@400;700&display=swap');

* {
  font-family: "Karla", sans-serif;
}

button:hover {
  cursor: pointer;
}

.modal {
  width: 400px;
  border: 3px solid black;
  border-radius: 10px;
}

header {
  display: grid;
  grid-template-columns: 1fr auto;
  padding: 20px 10px 0;
}

h1 {
  font-size: 32px;
  margin: 0;
  padding-left: 5px;
}

.body {
  padding: 0 15px 15px;
}

p {
  margin: 0;
}

.form-wrapper {
  margin: 20px 0;
}

.exercise-wrapper {
  border: 3px solid white;
  border-radius: 8px;
}

.exercise-label-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 10px;
}

.exercise-label-wrap:hover {
  cursor: pointer;
}

.exercise-info-tag {
  background: black;
  color: white;
  padding: 2px 8px;
  font-size: 14px;
  border-radius: 4px;
  font-size: 13px;
}

/* input wrapper all children hover cursor: pointer; */

.exercise-label {
  background: none;
  border-radius: 5px 5px 0 0;
}

.exercise-label:hover {
  cursor: pointer;
}

label {
  display: block;
  font-size: 18px;
  padding: 5px 0;
  font-weight: bold;
}

.sub-label {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: bold;
  margin-bottom: 2px;
}

input {
  font-size: 14px;
  padding: 10px;
  border-radius: 4px;
  border: 2px solid black;
}

.sub-input-opt,
.add-input-opt {
  border: 1px solid #333;
  color: #333;
  background: none;
  height: 30px;
  width: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.add-input-opt:hover,
.sub-input-opt:hover {
  font-weight: bold;
  border: 2px solid #333;
}

.alt-label {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
}

.alt-labels {
  display: grid;
  grid-template-columns: auto 1fr auto;
}

.super-set {
  border: 1px solid black;
  border-radius: 10px;
  padding: 10px;
  margin: 15px 0;
  position: relative;
}

.super-set span {
  position: absolute;
  right: 10px;
  background: black;
  color: white;
  height: 30px;
  width: 30px;
  text-align: center;
  line-height: 200%;
  border-radius: 50%;
}

.add-entry {
  display: grid;
  margin: 20px 0 10px;
}

.add-entry button {
  border: 2px solid black;
  padding: 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-radius: 6px;
}

.submit {
  margin: 0px 0;
  display: grid;
}

.btn-submit {
  border: unset;
  background: black;
  color: white;
  padding: 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-radius: 6px;
  transition: opacity 0.15s ease;
}

.btn-submit:hover {
  opacity: 0.75;
}

.sub-info-label {
  padding: unset;
  font-size: 14px;
}

.sub-info-wrap {
  display: grid;
  grid-template-columns: 2fr 1fr;
  padding: 10px;
  align-items: center;
}

.sub-info-right {
  display: grid;
  grid-template-columns: repeat(3, auto);
  grid-gap: 15px;
  align-items: center;
}

.sub-info-right input {
  padding: 5px;
  text-align: center;
}

.btn-add-exercise {
  border: unset;
  padding: 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-radius: 6px;
  background: unset;
  transition: all 0.15s ease-in-out;
}

.btn-add-exercise:hover {
  background: black;
  color: white;
}

.add-exercise {
  text-align: right;
  padding: 10px;
}

.hide-info {
  display: none;
}

.wrapper-active {
  border: 3px solid black;
}

.exercise-active {
  background: black;
  color: white;
}

h2 {
  font-size: 18px;
}

.create-exercise {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-gap: 5px;
  align-items: center;
  background: black;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-radius: 6px;
}

.create-exercise input {
  font-weight: bold;
}

.create-exercise button {
  border: unset;
  padding: 11px 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-radius: 4px;
}

.info-placeholder {
  font-size: 13px;
  padding-bottom: 5px;
}

.expand-info {
  display: none;
  border: unset;
  background: none;
}

.gg-chevron-down {
  box-sizing: border-box;
  position: relative;
  display: block;
  transform: scale(var(--ggs, 1));
  width: 22px;
  height: 22px;
  border: 2px solid transparent;
  border-radius: 100px;
}

.gg-chevron-down::after {
  content: "";
  display: block;
  box-sizing: border-box;
  position: absolute;
  width: 7px;
  height: 7px;
  border-bottom: 2px solid;
  border-right: 2px solid;
  transform: rotate(45deg);
  left: 6px;
  top: 4px;
}

.sub-info-select {
  grid-template-columns: auto 1fr;
}

.select-menu {
  display: inline-flex;
  align-items: center;
  position: relative;
  padding: 3px;
  border-radius: 5px;
}

.select-menu:hover {
  cursor: pointer;
  background-color: #eee;
}

[data-attr="unit"] {
  font-size: 14px;
  font-weight: bold;
}

.select-opts {
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 1px 1px 10px rgba(10, 10, 10, 0.1);
  display: none;
  position: absolute;
  background-color: white;
  top: 25px;
}

.select-opts label {
  font-size: 14px;
  padding: 6px 10px;
}

.select-opts label:hover {
  background-color: #eee;
  cursor: pointer;
}

.select-opts label:not(:last-child) {
  border-bottom: 1px solid #ddd;
}

              
            
!

JS

              
                const body = document.querySelector("body");
const modal = document.querySelector(".modal");
const prompt = document.getElementById("prompt");
const addExerciseBtn = document.querySelector(".btn-add-exercise");
const addEntry = document.querySelector(".add-entry");
const form = document.querySelector("form");
const submitBtn = document.querySelector(".btn-submit");

let exerciseWrapper;
let exerciseLabelWrap;
let exerciseLabel;
let exerciseInfo;

function addExercise(e) {
  e.preventDefault();
  if (e.key === "Enter") {
    return;
  }

  const exerciseInput = document.createElement("div");
  exerciseInput.classList.add("create-exercise");
  console.log(exerciseInput);
  exerciseInput.innerHTML = `<input id="exercise-name" placeholder="Exercise Name">
        <button id="add-exercise" class="btn-add">Add</button>`;

  if (prompt !== null) {
    prompt.remove();
  }

  addEntry.insertAdjacentElement("beforebegin", exerciseInput);

  const addExercise = document.getElementById("add-exercise");
  const exerciseId = document.getElementById("exercise-name");

  let exerciseName;
  let exerciseValue;

  addExercise.addEventListener("click", completeExercise);

  function completeExercise(e) {
    e.preventDefault();
    exerciseName = exerciseId.value;
    exerciseValue = exerciseId.value.toLowerCase();
    exerciseValue = exerciseValue.replace(/\s/g, "-");
    console.log(exerciseValue);

    const exerciseHTML = document.createElement("div");
    exerciseHTML.classList.add("exercise-wrapper");
    exerciseHTML.innerHTML = `<div class="exercise-label-wrap">
                                    <label class="exercise-label">${exerciseName}</label>
                                    <input type="hidden" name="${exerciseValue}" value="${exerciseValue}">
                                    <button class="expand-info"><i class="gg-chevron-down"></i></button>
                                    <span class="info-placeholder">Sets, Reps, Weight</span>
                                </div>
                                <div class='sub-info hide-info'>
                                    <div class="sub-info-wrap">
                                        <div class="sub-info-left">
                                            <label class="sub-info-label" for="">Sets</label>
                                        </div>
                                        <div class="sub-info-right">
                                            <button class="sub-input-opt" data-type="sub" data-name="sets" data-attr="${exerciseValue}">-</button>
                                            <input type="text" size="3" value="1" name="${exerciseValue}-sets">
                                            <button class="add-input-opt" data-type="add" data-name="sets" data-attr="${exerciseValue}">+</button>
                                        </div>
                                    </div>
                                    <div class="sub-info-wrap">
                                        <div class="sub-info-left">
                                            <label class="sub-info-label" for="">Reps</label>
                                        </div>
                                        <div class="sub-info-right">
                                            <button class="sub-input-opt" data-type="sub" data-name="reps" data-attr="${exerciseValue}">-</button>
                                            <input type="text" size="3" name="${exerciseValue}-reps" value="0">
                                            <button class="add-input-opt" data-type="add" data-name="reps" data-attr="${exerciseValue}">+</button>
                                        </div>
                                    </div>
                                    <div class="sub-info-wrap">
                                        <div class="sub-info-left">
                                            <label class="sub-info-label" for="">Weight</label>
                                        </div>
                                        <div class="sub-info-right sub-info-select">
                                            <input type="text" size="3" name="${exerciseValue}-weight" value="0">
                                            <div class="select-menu">
                                                <span data-attr="unit">lbs</span>
                                                <input type="hidden" value="lbs" name="${exerciseValue}-unit">
                                                <i class="gg-chevron-down"></i>
                                                <div class="select-opts">
                                                    <label>
                                                        <input type="hidden" value="lbs">
                                                        <span>lbs</span>
                                                    </label>
                                                    <label>
                                                        <input type="hidden" value="kgs">
                                                        <span>kgs</span>
                                                    </label>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                 `;
    if (document.querySelector(".create-exercise") !== null) {
      document.querySelector(".create-exercise").remove();
    }

    addEntry.insertAdjacentElement("beforebegin", exerciseHTML);

    exerciseWrapper = document.querySelectorAll(".exercise-wrapper"); // parentElem
    exerciseLabelWrap = document.querySelectorAll(".exercise-label-wrap"); // firstChildElem
    exerciseLabel = document.querySelectorAll(".exercise-label");
    exerciseInfo = document.querySelectorAll(".sub-info"); // lastChildElem

    exerciseLabelWrap.forEach((wrap) =>
      wrap.addEventListener("click", toggleExercise)
    );
    const subBtns = document.querySelectorAll("[data-type=sub]");
    const addBtns = document.querySelectorAll("[data-type=add]");

    subBtns.forEach((btn) => btn.addEventListener("click", subtractOne));
    addBtns.forEach((btn) => btn.addEventListener("click", addOne));

    // select menus
    const selectMenu = document.querySelectorAll(".select-menu");

    selectMenu.forEach((menu) =>
      menu.addEventListener("click", toggleSelectMenu)
    );

    const selectOps = document.querySelectorAll(".select-opts label");

    selectOps.forEach((opts) => opts.addEventListener("click", selectUnit));
  }
}

addExerciseBtn.addEventListener("click", addExercise);

function toggleExercise(e) {
  e.preventDefault();
  const parentElem = this.parentElement; // exerciseWrap
  const firstChildElem = parentElem.firstChild; // exerciseLabelWrap
  const lastChildElem = parentElem.lastChild; // exerciseInfo
  const inputInfo = parentElem.querySelector(".sub-info");

  // find exercise value
  let exerciseValue = firstChildElem.querySelector("input").name;

  if (!lastChildElem.classList.contains("hide-info")) {
    // there is nothing for exercise value
    let setValue =
      parentElem.querySelector(`input[name=${exerciseValue}-sets]`).value || "";
    let repValue =
      parentElem.querySelector(`input[name=${exerciseValue}-reps]`).value || "";
    let weightValue =
      parentElem.querySelector(`input[name=${exerciseValue}-weight]`).value ||
      "";
    let unitValue =
      parentElem.querySelector(`input[name=${exerciseValue}-unit]`).value || "";

    // creating span list to access in if/else blocks
    let spanList;
    let setSpan;
    let repSpan;
    let weightSpan;

    // when first creating span list, do this
    if (firstChildElem.querySelector(".exercise-info-tag") === null) {
      spanList = document.createElement("span");
      spanList.classList.add("exercise-info-tag");

      // get and pass info
      setSpan = `<span class="set-value">${setValue}</span>`;
      repSpan = `<span class="rep-value">${repValue}</span>`;
      weightSpan = `<span class="weight-value">${weightValue}${unitValue}</span>`;

      const infoPlaceholder = firstChildElem.querySelector(".info-placeholder");
      
      if (repValue === 0) {
        console.log(1);
        return;
      } else if (repValue > 0 && weightValue < 1) {
        console.log(2);
        infoPlaceholder.remove();
        spanList.innerHTML = `${setSpan} X ${repSpan}`;
        firstChildElem.insertAdjacentElement("beforeend", spanList);
      } else if (repValue > 0 && weightValue > 0) {
        console.log(3);
        infoPlaceholder.remove();
        spanList.innerHTML = `${setSpan} X ${repSpan} @ ${weightSpan}`;
        firstChildElem.insertAdjacentElement("beforeend", spanList);
      }
    } else if (firstChildElem.querySelector(".exercise-info-tag") !== null) {
      spanList = firstChildElem.querySelector(".exercise-info-tag");
    
      setSpan = `<span class="set-value">${setValue}</span>`;
      repSpan = `<span class="rep-value">${repValue}</span>`;
      weightSpan = `<span class="weight-value">${weightValue}${unitValue}</span>`;

      if (repValue === 0) {
        console.log(1);
        return;
      } else if (repValue > 0 && weightValue < 1) {
        console.log(2);
        spanList.innerHTML = `${setSpan} X ${repSpan}`;
        firstChildElem.insertAdjacentElement("beforeend", spanList);
      } else if (repValue > 0 && weightValue > 0) {
        console.log(3);
        spanList.innerHTML = `${setSpan} X ${repSpan} @ ${weightSpan}`;
        firstChildElem.insertAdjacentElement("beforeend", spanList);
      }
    }
    parentElem.classList.remove("wrapper-active");
    firstChildElem.classList.remove("exercise-active");
    lastChildElem.classList.add("hide-info");
  } else if (lastChildElem.classList.contains("hide-info")) {
    lastChildElem.classList.remove("hide-info");
    parentElem.classList.add("wrapper-active");
    firstChildElem.classList.add("exercise-active");
  }
}

function addOne(e) {
  e.preventDefault();
  let exerciseData = e.target.dataset.name;
  let exerciseValue = e.target.dataset.attr;
  let changeVal = document.querySelector(
    `[name="${exerciseValue}-${exerciseData}"]`
  );
  exerciseData === "weight"
    ? (changeVal.value = parseInt(changeVal.value) + 5)
    : changeVal.value++;
}

function subtractOne(e) {
  e.preventDefault();
  let exerciseData = e.target.dataset.name;
  let exerciseValue = e.target.dataset.attr;
  let changeVal = document.querySelector(
    `[name="${exerciseValue}-${exerciseData}"]`
  );
  
  if (changeVal.value >= 1) {
    if (exerciseData === "weight") {
      changeVal.value = parseInt(changeVal.value) - 5;
    } else {
      changeVal.value--;
    }
  } else {
    return;
  }
}

function toggleSelectMenu(e) {
  const selectOpts = this.querySelector(".select-opts");
  if (window.getComputedStyle(selectOpts).display === "none") {
    selectOpts.style.display = "block";
  } else if (selectOpts.style.display === "none") {
    selectOpts.style.display = "block";
  } else if (selectOpts.style.display === "block") {
    selectOpts.style.display = "none";
  }
}

function selectUnit() {
  const parentSelect = this.parentElement.parentElement;
  const unitValue = this.querySelector("input").value;
  parentSelect.querySelector('[data-attr="unit"]').innerText = `${unitValue}`;
  parentSelect.querySelector("input").value = `${unitValue}`;
}

function logWorkout(e) {
  e.preventDefault();
  const exercises = document.querySelectorAll(".exercise-wrapper");
  exercises.forEach((exercise) => exercise.remove());
}

submitBtn.addEventListener("click", logWorkout);

// disable enter key
document.addEventListener("keydown", function (e) {
  if (e.key === "Enter") {
    e.preventDefault();
    console.log(e);
  }
});

              
            
!
999px

Console