-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpp-assignment.html
More file actions
49 lines (43 loc) · 1.54 KB
/
pp-assignment.html
File metadata and controls
49 lines (43 loc) · 1.54 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
<!DOCTYPE html>
<html>
<head>
<title>News Reader</title>
</head>
<body>
<div id="main"></div>
<script>
// Module one output
var feed = "Obama visited Facebook headquarters: http://bit.ly/xyz @elversatile";
// Module Two
function extractFeedInfo(feed) {
return feed.split(" ");
}
var feedOutput = extractFeedInfo(feed);
var mainDiv = document.getElementById("main");
// Module three
function formattedText(output) {
for(var item of output) {
if(item === "http://bit.ly/xyz") {
var a = document.createElement('a');
a.setAttribute("href", item);
a.textContent = item;
mainDiv.appendChild(a);
} else if(item.includes('@')) {
var username = item.slice(1);
var a = document.createElement('a');
a.setAttribute("href", "http://twitter.com/" + username);
a.textContent = username
mainDiv.appendChild(a);
} else if(item[0] === item[0].toUpperCase()) {
var strong = document.createElement('strong');
strong.textContent = item;
mainDiv.appendChild(strong);
} else {
mainDiv.innerHTML += item;
}
}
}
formattedText(feedOutput);
</script>
</body>
</html>