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

              
                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css2?family=Rubik:wght@500&display=swap" rel="stylesheet">
<main id="wrapper">
  <div id="timer">
    <h1>Set custome times (in minutes)</h1>
    <div id="input-field">
      <div>
        <label>Pomodoro</label>
        <input id="pomodoro" placeholder="25mins default">
      </div>
      <div>
        <label>Short break</label>
        <input id="short-break" placeholder="5mins default">
      </div>

      <div>
        <label>Long break</label>
        <input id="long-break" placeholder="10mins default">
      </div>
    </div>
    <div id="display">Working 25:00</div>
    <div id="buttons">
      <button id="start">Start</button>
      <!--       <button id="pause">Pause</button> -->
      <button id="reset">Reset</button>
    </div>
  </div>

  <!--Todo app-->
  <div id="list">
    <div>
      <h1>My Todo List</h1>
      <div class="input-field">
        <input id="input" placeholder="Add a new todo">
        <span id="add-button">Add</span>
      </div>
    </div>
    <div id="bottom">
      <ul id="todo-list"></ul>
    </div>
  </div>
</main>
              
            
!

CSS

              
                /* Include the padding and border in an element's total width and height */
* {
  box-sizing: border-box;
}
#wrapper {
  display: flex;
  justify-content: center;
  justify-items: center;
  flex-wrap: wrap;
  text-align: center;
  margin: 64px auto;
  font-family: "Rubik", sans-serif;
}
#timer {
  flex-basis: 45%;
  display: flex;
  flex-direction: column;
  border: lightgray 2px solid;
  border-radius: 15px;
  margin-bottom: 16px;
}
#input-field {
  display: flex;
  justify-content: center;
  justify-items: center;
}
#display {
  background-color: #f83d55;
  font-size: 64px;
  margin: 24px 0;
  padding: 48px;
  color: white;
}
#buttons {
  margin-bottom: 8px;
}
label {
  text-align: center;
  font-size: 24px;
}
input,
#add-button {
  padding: 16px;
  text-align: center;
  font-size: 16px;
  width: 85%;
  margin: 8px 0;
  border: lightgray solid 1px;
  border-radius: 8px;
}
input:focus,
button:focus {
  outline: none;
}

button {
  padding: 8px 24px;
  border-radius: 10px;
}

/*TODO LIST STYLE*/
#list {
  flex: 45%;
  border: lightgray solid 1px;
  margin-left: 16px;
  border-radius: 15px;
}

/* Remove margins and padding from the list */
ul {
  margin: 0 22px;
  padding: 0;
}
/* Style the list items */
ul li {
  cursor: pointer;
  position: relative;
  padding: 12px 8px 12px 40px;
  list-style-type: none;
  background: #eee;
  font-size: 20px;
  transition: 0.2s;
  width: 100%;
  margin-left: 8px;
  border-radius: 8px;

  /* make the list items unselectable */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Set all odd list items to a different color (zebra-stripes) */
ul li:nth-child(odd) {
  background: #f9f9f9;
}

/* Darker background-color on hover */
ul li:hover {
  background: #ddd;
}

/* When clicked on, add a background color and strike out text */
ul li.checked {
  background: #888;
  color: #fff;
  text-decoration: line-through;
}

/* Add a "checked" mark when clicked on */
ul li.checked::before {
  content: "";
  position: absolute;
  border-color: #fff;
  border-style: solid;
  border-width: 0 2px 2px 0;
  top: 10px;
  left: 25px;
  transform: rotate(45deg);
  height: 15px;
  width: 7px;
}

/* add style for delete button */
.deleteBtn {
  position: absolute;
  right: 0;
  top: 0;
  padding: 12px 16px 12px 16px;
}

/* add style for add button*/
.input-field {
  margin-top: 32px;
  padding-top: 16px;
  display: flex;
  justify-content: center;
}
#add-button {
  flex-basis: 10%;
  background-color: #f83d55;
  color: white;
}

.toDo-Item {
  display: flex;
  margin-bottom: 8px;
}

              
            
!

JS

              
                console.clear();

const pomodoro = document.getElementById("pomodoro");
const shortBreak = document.getElementById("short-break");
const longBreak = document.getElementById("long-break");
const startBtn = document.getElementById("start");
const pauseBtn = document.getElementById("pause");
const resetBtn = document.getElementById("reset");

/*TODO LIST*/
let todoList = [];
const addButton = document.getElementById("add-button");
const inputElement = document.getElementById("input");
const listElement = document.getElementById("todo-list");

// render item of todo list
const renderTodoListItem = (item) => {
  //create div includes start button, li element and deletebutton
  const div = document.createElement("DIV");
  div.setAttribute("class", "toDo-Item");

  const node = document.createElement("LI"); // create li element
  const textnode = document.createTextNode(item.text); // create text in node
  node.setAttribute("id", `item-${item.id}`); // add unique id => helping on edit and remove for specific item
  node.setAttribute("class", "unchecked");
  node.appendChild(textnode); //add text to li element

  //create start button
  const startToDo = document.createElement("BUTTON");
  const startText = document.createTextNode("Start");
  startToDo.setAttribute("class", `startBtn`);
  startToDo.appendChild(startText);
  startToDo.addEventListener("click", () => {
    toggleButton();
    console.log("hi");
  });

  //create delete button and append it to each li element
  const nodeSpan = document.createElement("span"); //create span element
  const spanText = document.createTextNode("\u00D7"); // create delete icon by unicode
  nodeSpan.setAttribute("id", `deleteBtn-${item.id}`);
  nodeSpan.setAttribute("class", `deleteBtn`);
  nodeSpan.appendChild(spanText); //add delete icon to span element
  node.appendChild(nodeSpan); //add span with delete icon to li

  div.appendChild(startToDo);
  div.appendChild(node);

  // listElement.appendChild(startToDo);
  listElement.appendChild(div);

  //delete the Li element when click on delete button
  nodeSpan.addEventListener("click", () => {
    const buttonId = parseFloat(nodeSpan.id.split("-")[1]); //id of current delete button
    todoList = todoList.filter((el) => el.id !== buttonId);
    renderTodoList();
  });

  //toggle class to checked class when click on li element - text
  //need to find index of object to access inside the object
  node.addEventListener("click", () => {
    const textId = parseFloat(node.id.split("-")[1]);
    const index = todoList.findIndex((el) => el.id === textId);
    todoList[index].ischecked = !todoList[index].ischecked;
    if (todoList[index].ischecked) {
      node.classList.add("checked");
    } else {
      node.classList.remove("checked");
    }
  });
};

// render todo list in html
const renderTodoList = () => {
  listElement.innerHTML = ""; // clear the list element before rerender
  todoList.forEach((item) => {
    renderTodoListItem(item);
  });
};
// defined event click for add button
addButton.addEventListener("click", () => {
  const inputValue = inputElement.value; // get value from input
  if (inputValue === "") return;
  todoList.push({ text: inputValue, id: Math.random(), ischecked: false }); // push object item to todolist
  inputElement.value = ""; //clear out input field
  renderTodoList(); // rerender the todoList Element
});

/*Pomodoro timer*/
let countdown;
const second = 1000;
const minute = 60000;

const initialValue = {
  timer: 25 * minute,
  shortBreak: 5 * minute,
  longBreak: 10 * minute,
  interval: 4,
  isShortBreak: false,
  isLongBreak: false
};

const pomodoroConfig = Object.assign({}, initialValue); //copy initialValue object and wont modifiy its values

//Main function: timer, start countdown and display update
function workTimer() {
  clearInterval(countdown);
  countdown = setInterval(() => {
    pomodoroConfig.timer = pomodoroConfig.timer - second;
    displayTimeLeft(pomodoroConfig.timer, "Working");

    if (!pomodoroConfig.timer) {
      //pomodoroConfig.timer === 0
      clearInterval(countdown);
      pomodoroConfig.isShortBreak = true;
      pomodoroConfig.interval = pomodoroConfig.interval - 1;
    }
    if (
      pomodoroConfig.isShortBreak &&
      pomodoroConfig.shortBreak &&
      pomodoroConfig.interval > 0
    ) {
      pomodoroConfig.isShortBreak = false;
      shortBreakTimer();
    }
    if (pomodoroConfig.interval === 0) {
      longBreakTimer();
      pomodoroConfig.interval = initialValue.interval;
      displayTimeLeft(initialValue.workTime, "Working");
    }
  }, second);
}

function shortBreakTimer() {
  clearInterval(countdown);
  countdown = setInterval(() => {
    pomodoroConfig.isShortBreak = true;
    pomodoroConfig.shortBreak = pomodoroConfig.shortBreak - second;
    displayTimeLeft(pomodoroConfig.shortBreak, "Break");
    if (!pomodoroConfig.shortBreak) {
      pomodoroConfig.isShortBreak = false;
      clearInterval(countdown);
      workTimer();
      pomodoroConfig.timer = initialValue.timer;
      pomodoroConfig.shortBreak = initialValue.shortBreak;
    }
  }, second);
}

function longBreakTimer() {
  clearTimeout(countdown);
  countdown = setInterval(() => {
    pomodoroConfig.longBreak = pomodoroConfig.longBreak - second;
    displayTimeLeft(pomodoroConfig.longBreak, "Long Break");
    if (pomodoroConfig.longBreak == 0) {
      clearInterval(countdown);
    }
  }, second);
}

function displayTimeLeft(miliseconds, type) {
  const minutes = Math.floor(miliseconds / minute);
  const remainderSeconds = (miliseconds / second) % 60;
  const display = `${type} ${minutes}:${
    remainderSeconds < 10 ? "0" : ""
  }${remainderSeconds}`; //template literal
  document.getElementById("display").innerHTML = display;
}

//function toggle start/pause timer
function toggleButton() {
  startBtn.textContent = "Pause";
  if (!pomodoroConfig.isPause) {
    if (pomodoroConfig.isShortBreak) {
      shortBreakTimer();
    } else {
      workTimer();
    }
  } else {
    startBtn.textContent = "Resume";
    clearInterval(countdown);
    if (pomodoroConfig.timer === 0) {
      pomodoroConfig.timer = initialValue.timer;
    }
    if (pomodoroConfig.shortBreak === 0) {
      pomodoroConfig.shortBreak = initalValue.shortBreak;
    }
  }
  pomodoroConfig.isPause = !pomodoroConfig.isPause;
}

//Buttons function and display
startBtn.addEventListener("click", () => {
  toggleButton();
});

resetBtn.addEventListener("click", () => {
  clearInterval(countdown);
  startBtn.textContent = "Start";
  pomodoroConfig.timer = initialValue.timer;
  pomodoroConfig.shortBreak = initialValue.shortBreak;
  pomodoroConfig.longBreak = initialValue.longBreak;
  pomodoroConfig.isPause = false;
  displayTimeLeft(initialValue.timer, "Working");
});

//Assign value to timer, break and long break from user input
pomodoro.addEventListener("input", () => {
  // customizedTime();
  if (pomodoro.value !== "" || pomodoro.value !== "25") {
    initialValue.timer = parseInt(pomodoro.value) * minute;
    pomodoroConfig.timer = initialValue.timer;
  }
  if (pomodoro.value === "") {
    initialValue.timer = 25 * minute;
    pomodoroConfig.timer = initialValue.timer; //default value
  }
  console.log(event.target.value, pomodoroConfig.timer, initialValue.timer);
});

shortBreak.addEventListener("input", () => {
  if (shortBreak.value !== "" || shortBreak.value !== "25") {
    initialValue.shortBreak = parseInt(shortBreak.value) * minute;
    pomodoroConfig.shortBreak = initialValue.shortBreak;
  }
  if (shortBreak.value === "") {
    initialValue.shortBreak = 5 * minute;
    pomodoroConfig.shortBreak = initialValue.shortBreak; //default value
  }
  console.log(
    event.target.value,
    pomodoroConfig.shortBreak,
    initialValue.shortBreak
  );
});

longBreak.addEventListener("input", () => {
  if (longBreak.value !== "" || longBreak.value !== "25") {
    initialValue.longBreak = parseInt(longBreak.value) * minute;
    pomodoroConfig.longBreak = initialValue.longBreak;
  }
  if (longBreak.value === "") {
    initialValue.longBreak = 10 * minute;
    pomodoroConfig.longBreak = initialValue.longBreak; //default value
  }
  console.log(
    event.target.value,
    pomodoroConfig.longBreak,
    initialValue.longBreak
  );
});

              
            
!
999px

Console