-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirstletter.html
54 lines (45 loc) · 1.08 KB
/
firstletter.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
<html lang="en">
<head>
<title>Document</title>
</head>
<style>
body {
background-color: white;
}
div {
margin: 120px;
}
p {
padding-top: 20px;
height: 60px;
width: 80px;
font-size: 35px;
text-align: center;
background-color: #70db70;
border: 2px #1f7a1f solid;
outline: none;
border-radius: 50px;
}
</style>
<body>
<div id="div1"></div>
</body>
<script>
var getInitials = function (string) {
var names = string.split(" "),
initials = names[0].substring(0, 1).toUpperCase();
if (names.length > 1) {
initials += names[names.length - 1].substring(0, 1).toUpperCase();
}
return initials;
};
// console.log(getInitials("Mark Zucker"));
// console.log(getInitials("FirstName MiddleName LastName"));
// console.log(getInitials("1stName 2ndName 3rdName 4thName 5thName"));
var para = document.createElement("p");
var alpha = document.createTextNode(getInitials("Sid there"));
para.appendChild(alpha);
var element = document.getElementById("div1");
element.appendChild(para);
</script>
</html>