-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
98 lines (85 loc) · 3.97 KB
/
index.html
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>age calculator</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<style>
@media(max-width:768){
#my-box{margin:1rem;}
}
</style>
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-6 offset-1" id="my-box"> <!--md = mid break point-->
<!-- title name card and card box -->
<div class="card mt-5">
<div class="card-body">
<h5 class="card-title text-center text-uppercase">Age calculator</h5>
<p class="text-secondary"><small>Provide your age</small></p>
<!-- date -->
<div class="col-md-4">
<div class="form-group">
<input type="text" placeholder="Date" class="form-group" id="nameField">
</div>
</div>
<!-- month -->
<div class="col-md-4 mt-3">
<select id="monthField" name="" id="">
<option value="" selected disabled>Month</option>
<option value="January">January</option>
<option value="Febuary">Febuary</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
</div>
<!-- Year -->
<div class="col-md-4 mt-3">
<div class="form-group">
<input type="text" placeholder="Year" class="form-group" id="yearField">
</div>
</div>
</div>
<!-- button -->
<button onclick="calculate()" class="btn btn-outline-info btn-sm">Calculate</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm"
crossorigin="anonymous"></script>
<script>
const calculate = () => {
let date = document.getElementById("nameField").value
let month = document.getElementById("monthField").value
let year= document.getElementById("yearField").value
console.log(name)
console.log(month)
console.log(year)
if(date>31){
alert("invalid date")
return;
}
let dob = new Date(`${date} ${month} ${year}`)
let now= new Date()
let difference = now - dob;
let days = Math.floor(difference/(1000*60*60*24*365))
alert(`You are ${days} years old.`)
console.log(dob)
}
</script>
</body>
</html>