-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
70 lines (57 loc) · 1.76 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
const inputEl=document.querySelector("input#userName");
const buttonEl=document.querySelector("button");
const greetingEl=document.querySelector("#greeting")
const bgChangeEl=document.querySelector("#bgChange")
buttonEl.addEventListener('click',()=>{
showWelcomeCard()
});
//capitalizing user input
function capitalizeWords(words){
const splitting=words.split(" ")
const mapping=splitting.map((words) =>{
return words.charAt(0).toUpperCase()+ words.slice(1)
});
return mapping.join(" ")
}
//changing bg color when clicking submit
bgChangeEl.addEventListener('click',()=>{
console.log(document.body.style.backgroundColor="pink");
})
//using classlist
buttonEl.classList.add("text-white","font-bold")
// setting timer
setTimeout(()=>{
buttonEl.classList.remove("text-white")
buttonEl.classList.add("bg-red-300")
},5000)
// setInterval(()=>{
// })
document.addEventListener("DOMContentLoaded",()=>{
//hiding the greeting message element
greetingEl.style.display = "none";
// greetingEl.style.visibility="hidden"
//working with keyboard values
document.addEventListener("keydown", (event) => {
if (event.code === "Enter") {
showWelcomeCard()
}
// console.log("You have pressed Enter key");
// } else {
// console.log(`You pressed key, ${event.key}`);
// }
});
})
function showWelcomeCard(){
if (inputEl.value.length < 3 || inputEl.value.length > 20) {
alert("Can't get your name‼️");
return;
} else {
// alert("Hello " + capitalizeWords(inputEl.value));
greetingEl.innerText = `😀Hello ${capitalizeWords(
inputEl.value
)}, Welcome back!!!`;
greetingEl.style.display = "block";
// greetingEl.style.visibility="visible"
}
console.log(inputEl.value.length);
}