Create a simple calendar application that allows a user to save events for each hour of the day. This app will run in the browser and feature dynamically updated HTML and CSS powered by jQuery.
The starter code uses the Moment.js (Links to an external site.) library to work with date and time, but feel free to use a different JavaScript solution to handle this functionality since Moment.js is considered a "legacy" project. Learn more about some alternative solutions in the Moment.js project status page.
Make sure to clone the starter code repository and make your own repository with the starter code. Do not fork the starter code repository!
Before you start, clone the starter code.
AS AN employee with a busy schedule
I WANT to add important events to a daily planner
SO THAT I can manage my time effectively
GIVEN I am using a daily planner to create a schedule
WHEN I open the planner
THEN the current day is displayed at the top of the calendar
WHEN I scroll down
THEN I am presented with time blocks for standard business hours
WHEN I view the time blocks for that day
THEN each time block is color-coded to indicate whether it is in the past, present, or future
WHEN I click into a time block
THEN I can enter an event
WHEN I click the save button for that time block
THEN the text for that event is saved in local storage
WHEN I refresh the page
THEN the saved events persist
- Solution URL: https://github.com/anakela/work-day-scheduler
- Live Site URL: https://anakela.github.io/work-day-scheduler/
- Semantic HTML5 Markup
- CSS
- JavaScript
- jQuery
- Moment.js
- Bootstrap
- Font Awesome
During this assignment, I learned how to loop through the various description
textareas in order to save content in them using the saveBtn
button.
// When the save button is clicked, store the data in localstorage.
$(".saveBtn").on("click", function () {
// Set the key and value for input.
let keyName = $(this).siblings(".description").attr("id");
console.log(keyName);
let valueName = $(this).siblings(".description").val();
// Call the storeEvent function with fresh user input.
storeEvent(keyName, valueName);
});
I also get more experience storing items to localStorage
, then pulling them from localStorage
for display.
// Store events in local storage.
function storeEvent(keyName, valueName) {
let eventDesc = JSON.parse(localStorage.getItem("eventDesc"));
if (eventDesc === null) {
eventDesc = {};
}
eventDesc[keyName] = valueName;
localStorage.setItem("eventDesc", JSON.stringify(eventDesc));
displayEvent();
};
// Display events on the work day scheduler.
function displayEvent() {
let eventDesc = JSON.parse(localStorage.getItem("eventDesc"));
if (eventDesc === null) {
return;
}
let textArea = $(".description");
for (let i = 0; i < textArea.length; i++) {
let hour = $(textArea[i]).attr("id");
if (eventDesc[hour]) {
$(textArea[i]).val(eventDesc[hour]);
};
};
};
I struggled in this particular exercise with pulling data that was stored in localStorage
and displaying them on the page. I'd like to do more of this in the future to solidify my understanding of this and similar processes.
- Stack Overflow: Live Clock Moment.js
- Stack Overflow: Use Font Awesome Icon As Favicon
- Stack Overflow: How can I use localstorage to display the values on my web page using JavaScript?
- Stack Overflow: Setting and getting localStorage with jQuery
- Stack Overflow: How to get the exact local time of client?
- Stack Overflow: How to compare time in javascript?
- Stack Overflow: How can I change an element's class with JavaScript?
- MDN Web Docs: Storage.getItem()
- MDN Web Docs: Date.prototype.toLocaleDateString()
- MDN Web Docs: Date.prototype.getHours()
- MDN Web Docs: Date.prototype.toLocaleTimeString()
- MDN Web Docs: Element.innerHTML
- Font Awesome Icon Downloader
- jQuery: .text()
- jQuery: Category: Selectors
- jQuery: .each()
- jQuery: .replaceWith()
- jQuery: .removeClass()
- jQuery: .on()
- Font Awesome
- Use toLocaleDateString to Format JavaScript Dates
- W3Schools: JavaScript Date Formats
- W3Schools: Window localStorage
- W3Schools: JavaScript Date getMinutes()
- W3Schools: Javascript Date getHours()
- W3Schools: jQuery Selectors
- “local storage getitem and setitem jquery” Code Answer’s
- JavaScript Convert String to Number
- Tutorial Republic: jQuery Add and Remove CSS Classes
- Fellow Bootcampers:
- Nifer Kilakila
- Ivy Chang
- Nolan Spence
- Michael Barrett
- Kevin Muehlbauer
- Bobbi Tarkany (Tutor)
- AskBCS Slack Channel