-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (29 loc) · 1.25 KB
/
index.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
import { initialDataQuestions } from "./data/questions.js";
import { renderQuestions } from "./features/question.js";
let appQuestions = initialDataQuestions;
const questionFormElement = document.getElementById("question-form");
const questionsContainerElement = document.getElementById(
"questions-container"
);
const copyrightYearElement = document.getElementById("copyright-year");
const addNewQuestion = (event) => {
event.preventDefault();
// Get form input values
const formData = new FormData(event.target);
const title = formData.get("question-title");
const description = formData.get("question-description");
const newQuestion = { title, description };
// Append new question to the existing app questions data
const newDataQuestions = [...appQuestions, newQuestion];
// Replace existing app questions with the new data
// Later can be sync with the database or web storage
appQuestions = newDataQuestions;
// Re-render questions data
renderQuestions(questionsContainerElement, appQuestions);
};
const renderApp = () => {
copyrightYearElement.innerText = new Date().getFullYear();
renderQuestions(questionsContainerElement, appQuestions);
questionFormElement.addEventListener("submit", addNewQuestion);
};
renderApp();