-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmental_diary.js
More file actions
64 lines (54 loc) · 2.34 KB
/
mental_diary.js
File metadata and controls
64 lines (54 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const entryForm = document.querySelector(`#entryForm`);
const entryResultsSection = document.querySelector(`#entryResultsSection`);
const entryResultItem = document.querySelector(`.entryResultItem`);
const entryResultRow = document.querySelector(`.entryResultRow`);
const getEntryTitle = document.getElementsByClassName(`entry-text-title`);
const getEntryText = document.getElementsByClassName(`entry-text-box`);
function addEntryToDom(event) {
event.preventDefault();
const d = new Date();
const month = new Array();
month[0] = 'January';
month[1] = 'February';
month[2] = 'March';
month[3] = 'April';
month[4] = 'May';
month[5] = 'June';
month[6] = 'July';
month[7] = 'August';
month[8] = 'September';
month[9] = 'October';
month[10] = 'November';
month[11] = 'December';
const n = month[d.getMonth()];
const day = d.getDay();
const year = d.getFullYear();
const heading = document.createElement(`h2`);
heading.className = `heading-results`;
heading.textContent = `Journal Entries`;
entryResultRow.insertAdjacentElement(`beforebegin`, heading)
// Adding Div
const entryDiv = document.createElement(`div`);
entryDiv.className = `single-entry-div`;
entryResultRow.appendChild(entryDiv);
// Adding Div Element h3
const entryHeading = document.createElement(`h3`);
entryHeading.className = `single-entry-heading`;
entryHeading.textContent = getEntryTitle[0].value;
entryDiv.appendChild(entryHeading);
// Adding Div Element Date
const entryDate = document.createElement(`p`);
entryDate.className = `single-entry-date`;
// eslint-disable-next-line no-cond-assign
if ((getEntryTitle[0].value = getEntryTitle[0].value)) {
entryDate.textContent = `Date Added: ${day} ${n} ${year}`;
entryDiv.appendChild(entryDate);
}
// Adding Div Element paragraph
const entryParagraph = document.createElement(`p`);
entryParagraph.className = `single-entry-text`;
entryParagraph.textContent = getEntryText[0].value;
entryDiv.appendChild(entryParagraph);
getEntryText[0].value = ``;
}
entryForm.addEventListener(`submit`, addEntryToDom);