-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (48 loc) · 1.73 KB
/
script.js
File metadata and controls
64 lines (48 loc) · 1.73 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 usernameInput = document.getElementById('usernameInput');
const postInput = document.getElementById('postInput');
const postBtn = document.getElementById('postBtn');
const postFeed = document.getElementById('posts');
const username = document.getElementById('username');
const postText = document.getElementById('postText');
const addPostBtn = document.getElementById('add')
const main = document.getElementById('main')
function getCurrentFormattedDateTime() {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0'); // getMonth() is zero-based
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
return `${year}/${month}/${day} ${hours}:${minutes}`;
}
function publishPost(){
var time = getCurrentFormattedDateTime();
var usernameInputValue = usernameInput.value;
// console.log(usernameInputValue)
var postInputValue = postInput.value;
//console.log(postInputValue)
if(usernameInputValue !== '' && postInputValue !== ''){
postFeed.insertAdjacentHTML('afterbegin', `
<div class="post">
<h3>@${usernameInputValue}</h3>
<p>${postInputValue}</p>
<p class="time">${time}</p>
</div>
`);
postInput.value = ''
main.style.display = 'none'
}
}
function showOrHideMain(){
if (main.style.display === 'none'){
main.style.display = 'flex'
}
else if (main.style.display ===''){
main.style.display = 'flex'
}
else {
main.style.display = 'none'
}
}
postBtn.addEventListener('click' , publishPost)
addPostBtn.addEventListener('click' , showOrHideMain)