forked from StefanPougatchev/5-Minute-Journal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
292 lines (228 loc) · 9.34 KB
/
main.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// selecting body section on HTML
const body = document.querySelector('body');
// creating the mainDiv that we will be storing the subsequent div areas in
const mainDiv = document.createElement('div');
mainDiv.className = 'mainContentArea';
body.appendChild(mainDiv);
//* ----------------- dateArea inside mainDiv -----------------
// creating the date Area nested inside mainDiv
const dateDiv = document.createElement('div');
dateDiv.id = 'dateArea';
mainDiv.appendChild(dateDiv);
// declaring variable dateDay and appending it to dateDiv
const dateDay = document.createElement('h3');
dateDay.textContent = new Date().toDateString();
dateDiv.appendChild(dateDay);
//* -------create Quote Area nested inside the mainDiv----------
const randomNum = getRandomArbitrary(0, 1643);
function fetchQuote() {
const quoteDiv = document.createElement('div');
quoteDiv.id = 'quoteArea';
mainDiv.appendChild(quoteDiv);
let quotes;
let authorText;
let quoteText;
const displayQuote = document.createElement('p');
// displayQuote.textContent = quote2;
quoteDiv.appendChild(displayQuote);
const authorNameDisplay = document.createElement('p');
authorNameDisplay.id = 'authorName';
quoteDiv.appendChild(authorNameDisplay);
fetch('https://type.fit/api/quotes')
.then((res) => res.json())
.then((data) => (quotes = data))
.then(() => (quoteText = quotes[randomNum].text))
.then(() => (displayQuote.textContent = quoteText))
.then(() => (authorText = quotes[randomNum].author))
.then(() => (authorNameDisplay.textContent = ` - ${authorText} -`));
}
fetchQuote();
// const quoteText = document.createElement("p");
// quoteText.textContent = quote2 ? quote2 : "";
// quoteDiv.appendChild(quoteText);
// create the DaytimeContent area
// const quoteAuthor = document.createElement('p');
// includes three 3 nested divs gratefulArea, greatArea,Daily Affirmations
const daytimeContent = document.createElement('div');
daytimeContent.id = 'daytimeContent';
mainDiv.appendChild(daytimeContent);
//* ----------------- GrateFulArea -----------------
// gratefulArea with a nested Ordered List and heading
const gratefulDiv = document.createElement('div');
gratefulDiv.id = 'gratefulArea';
daytimeContent.appendChild(gratefulDiv);
// h2 heading for gratful Div
const gratefulHeading = document.createElement('h2');
gratefulHeading.textContent = 'I am grateful for...';
gratefulDiv.appendChild(gratefulHeading);
// ordered list for gratful Div
const gratefulList = document.createElement('ol');
gratefulList.className = 'input-list';
gratefulDiv.appendChild(gratefulList);
// input field
// const gratefulInput = document.createElement("input");
// gratefulInput.type = "text";
// gratefulDiv.appendChild(gratefulInput);
const storageGrateful = {};
for (let i = 0; i < 3; i++) {
const li = document.createElement('li');
// li.textContent = gratefulInput;
gratefulList.appendChild(li);
const gratefulInput = document.createElement('input');
gratefulInput.id = `Grateful${i}`
li.appendChild(gratefulInput);
storageGrateful[i] = gratefulInput.value;
}
//* ----------------- Make today great area -----------------
// makeTodayGreatArea with a nested Ordered List and heading
const todayGreatDiv = document.createElement('div');
todayGreatDiv.id = 'todayGreatArea';
daytimeContent.appendChild(todayGreatDiv);
// h2 heading for make today great
const todayGreatHeading = document.createElement('h2');
todayGreatHeading.textContent = 'What would make today great?';
todayGreatDiv.appendChild(todayGreatHeading);
// ordered list for make today great
const todayGreatList = document.createElement('ol');
todayGreatList.className = 'input-list';
todayGreatDiv.appendChild(todayGreatList);
// input field
// const gratefulInput = document.createElement("input");
// gratefulInput.type = "text";
// gratefulDiv.appendChild(gratefulInput);
const storageToday = {};
for (let i = 0; i < 3; i++) {
const li = document.createElement('li');
// li.textContent = gratefulInput;
todayGreatList.appendChild(li);
const todayGreatInput = document.createElement('input');
todayGreatInput.id = `todayGreat${i}`;
li.appendChild(todayGreatInput);
storageToday[i] = todayGreatInput.value;
}
//* ----------------- daily Affirmations -----------------
// dailyAffirmations Area with a nested Ordered List and heading
const dailyAffirmationsDiv = document.createElement('div');
dailyAffirmationsDiv.id = 'dailyAffirmationsArea';
daytimeContent.appendChild(dailyAffirmationsDiv);
// h2 heading for dailyAffirmations
const dailyAffirmationsHeading = document.createElement('h2');
dailyAffirmationsHeading.textContent = 'Daily affirmations. I am ...';
dailyAffirmationsDiv.appendChild(dailyAffirmationsHeading);
// ordered list for dailyAffirmations
const dailyAffirmationsList = document.createElement('ol');
dailyAffirmationsList.className = 'input-list';
dailyAffirmationsDiv.appendChild(dailyAffirmationsList);
// input field
// const gratefulInput = document.createElement("input");
// gratefulInput.type = "text";
// gratefulDiv.appendChild(gratefulInput);
const storageAffirmation = {};
for (let i = 0; i < 2; i++) {
const li = document.createElement('li');
// li.textContent = gratefulInput;
dailyAffirmationsList.appendChild(li);
const dailyAffirmationsInput = document.createElement('input');
dailyAffirmationsInput.id = `dailyAffirmations${i}`;
li.appendChild(dailyAffirmationsInput);
storageAffirmation[i] = dailyAffirmationsInput.value;
}
//* ----------------- Nighttime Content -----------------
// create the nighttimeContent div section, which will showcase it's own entries
// includes 2 nested areas amazingThingsArea today, howToMakeitBetterArea
const nighttimeContent = document.createElement('div');
nighttimeContent.id = 'nighttimeContent';
mainDiv.appendChild(nighttimeContent);
//* ----------------- Amazing Things Area -----------------
// create div section 3 amazing things that happened today
const amazingThingsArea = document.createElement('div');
amazingThingsArea.id = 'inputResponses';
nighttimeContent.appendChild(amazingThingsArea);
// h2 heading for amazingThingsArea
const amazingThingsHeading = document.createElement('h2');
amazingThingsHeading.textContent = '3 Amazing things that happened today...';
amazingThingsArea.appendChild(amazingThingsHeading);
// ordered list for amazingThingsHeading
const amazingThingsList = document.createElement('ol');
amazingThingsList.className = 'input-list';
amazingThingsArea.appendChild(amazingThingsList);
const storageAmazing = {};
for (let i = 0; i < 3; i++) {
const li = document.createElement('li');
// li.textContent = gratefulInput;
amazingThingsList.appendChild(li);
const amazingList = document.createElement('input');
amazingList.id = `amazing${i}`;
li.appendChild(amazingList);
storageAmazing[i] = amazingList.value;
}
//* ----------------- howToMakeitBetterArea Area -----------------
// create section; how could I have made today even better
const howToMakeitBetterArea = document.createElement('div');
howToMakeitBetterArea.id = 'inputResponses';
nighttimeContent.appendChild(howToMakeitBetterArea);
// h2 heading for howToMakeHeading
const howToMakeHeading = document.createElement('h2');
howToMakeHeading.textContent = 'How could I have made today even better?';
howToMakeitBetterArea.appendChild(howToMakeHeading);
// ordered list for howToMakeHeading
const howToMakeList = document.createElement('ol');
howToMakeList.className = 'input-list';
howToMakeitBetterArea.appendChild(howToMakeList);
const storageMakeBetter = {};
for (let i = 0; i < 2; i++) {
const li = document.createElement('li');
// li.textContent = gratefulInput;
howToMakeList.appendChild(li);
const howToList = document.createElement('input');
howToList.id = `toList${i}`;
li.appendChild(howToList);
storageMakeBetter[i] = howToList.value;
}
//* ----------------- Object to save info -----------------
// const storage = {
// // 1:
// }
//* ----------------- Save button -----------------
const saveButton = document.createElement('BUTTON');
saveButton.id = 'save-button';
saveButton.textContent = 'Save';
mainDiv.appendChild(saveButton);
function getRandomArbitrary(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
//* ----------------- Fetch Call -----------------
saveButton.addEventListener('click', () => {
for (let i = 0; i < 2; i++) {
storageAffirmation[i] = document.getElementById(`dailyAffirmations${i}`).value;
storageMakeBetter[i] = document.getElementById(`toList${i}`).value;
// storageMakeBetter[i] = howToList.value;
}
for (let i = 0; i < 3; i++) {
storageGrateful[i] = document.getElementById(`Grateful${i}`).value;
storageToday[i] = document.getElementById(`todayGreat${i}`).value;
storageAmazing[i] = document.getElementById(`amazing${i}`).value;
}
});
// `Grateful${i}`
// `todayGreat${i}`;
// `dailyAffirmations${i}`;
// `amazing${i}`;
// `toList${i}`;
console.log(storageGrateful); // 3
console.log(storageToday); // 3
console.log(storageAffirmation); // 2
console.log(storageAmazing); // 3
console.log(storageMakeBetter); // 2
// fetch("https://type.fit/api/quotes")
// .then(function (response) {
// return response.json();
// })
// .then(function (data) {
// let quote = data[randomNum].text;
// let author = data[randomNum].author;
// let arr = [quote, author];
// console.log(arr);
// });
// console.log(quote);
// console.log(data[randomNum][text])