-
Notifications
You must be signed in to change notification settings - Fork 8
/
script.js
64 lines (49 loc) · 2.24 KB
/
script.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
document.addEventListener('DOMContentLoaded', function() { // This means that your Javascript will only start working once your entire webpage has finised loading all the content from the server
const toggleDarkModeBtn = document.getElementById('toggleDarkMode');
const body = document.body;
const projectItems = document.querySelectorAll(".project-item");
const formFeedback = document.getElementById('formFeedback');
const contactForm = document.getElementById('contactForm');
//Toggle Dark Mode code starts from here
toggleDarkModeBtn.addEventListener('click', function(){
body.classList.toggle("dark-mode");
});
//Form Validation
contactForm.addEventListener('submit', function(event) {
event.preventDefault(); // Won't submit until all the code inside the function is run.
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
//AND( && ) OR( || ) NOT(!)
//= Assignment Operator.Checks VALUE
//== Comparison Operator
//=== EQUALITY Operator (TRUE/FAlSE)
//JS has 3 types of Pop UPs
//Alert BOX - alert()
//Confirm BOX - confirm()
//User Input BOX - prompt()
if (name === "" || email === "" || message === ""){
alert("Please fill out all the fields");
}
else if(!validateEmail(email)){ //WHEN THE Condition here will be false, Please enter a valid email will not be printed
alert("Please enter a valid email");
}
else{
contactForm.reset();
}
}); //CONTACT FORM VALIDATION CLOSE
function validateEmail(email){
const emailpattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; //smallest domain is .co longest 6 characters
return emailpattern.test(email); //THIS WILL ONLY RETURN EITHER TRUE OR FALSE
}
function greet(){
const userName = prompt("Please enter your name:");
if(userName){
alert(`Hello, ${userName}, Welcome to my portfolio Website! ` );
}
else{
alert(`Hello, you didn't enter your name! ` );
}
}
greet();
});