scrimba
JS Deep Dive
Google Keep
Google Keep - Displaying Notes in the App
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Google Keep - Displaying Notes in the App
AboutCommentsNotes
Google Keep - Displaying Notes in the App
Expand for more info
app.js
run
preview
console
class App {
constructor() {
this.notes = [];

this.$form = document.querySelector("#form");
this.$noteTitle = document.querySelector("#note-title");
this.$noteText = document.querySelector("#note-text");
this.$formButtons = document.querySelector("#form-buttons");

this.addEventListeners();
}

addEventListeners() {
document.body.addEventListener("click", event => {
this.handleFormClick(event);
});

this.$form.addEventListener("submit", event => {
event.preventDefault();
const title = this.$noteTitle.value;
const text = this.$noteText.value;
const hasNote = title || text;
if (hasNote) {
// add note
this.addNote({ title, text });
}
});
}

handleFormClick(event) {
const isFormClicked = this.$form.contains(event.target);

if (isFormClicked) {
this.openForm();
} else {
this.closeForm();
}
}

openForm() {
this.$form.classList.add("form-open");
this.$noteTitle.style.display = "block";
this.$formButtons.style.display = "block";
}

closeForm() {
this.$form.classList.remove("form-open");
this.$noteTitle.style.display = "none";
this.$formButtons.style.display = "none";
}

addNote(note) {
const newNote = {
title: note.title,
text: note.text,
color: "white",
id: this.notes.length > 0 ? this.notes[this.notes.length - 1].id + 1 : 1
};
this.notes = [...this.notes, newNote];
console.log(this.notes);
}
}

new App();
Console
/index.html
-9:18