-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret.js
45 lines (34 loc) · 1.23 KB
/
secret.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
// Get the "Add a Quote" button
const addButton = document.querySelector('button');
// Add an event listener to the button
addButton.addEventListener('click', function () {
// Get the home section
const homeSection = document.querySelector('#home');
// Get inputs from the user
const quote = prompt("Enter a quote:");
const author = prompt("Enter the author:");
// Create a new blockquote element
const newQuote = document.createElement('blockquote');
newQuote.textContent = `"${quote}" - ${author}`;
// Insert the new quote before the button
homeSection.insertBefore(newQuote, addButton);
});
// Get the form element
const form = document.querySelector('form');
// Add an event listener to the form
form.addEventListener('submit', function (event) {
// Prevent the default form submission behavior
event.preventDefault();
// Get the form data
const formData = new FormData(form);
// Log the form data to the console
console.log({
name: formData.get('name'),
email: formData.get('email'),
message: formData.get('message')
});
// Reset the form
form.reset();
// Alert the user that the message has been sent
alert('Message sent!');
});