-
Notifications
You must be signed in to change notification settings - Fork 0
/
factoftheday.html
52 lines (45 loc) · 1.58 KB
/
factoftheday.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fact of the Day</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Fact of the Day</h1>
</header>
<div class="container">
<div id="fact-container">
<!-- Fact of the day will be displayed here -->
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
function loadRandomAddedFact() {
$.getJSON('Facts0V2.json', function(data) {
console.log('JSON Data Received:', data);
var addedFacts = data.filter(function(fact) {
return fact.Added === true;
});
var randomIndex = Math.floor(Math.random() * addedFacts.length);
var randomFact = addedFacts[randomIndex];
displayFact(randomFact);
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
console.log('JSON Request Failed:', err);
});
}
function displayFact(fact) {
// Display the fact in the fact-container
// Modify this part based on your needs
var factContainer = $('#fact-container');
factContainer.html('<p>' + fact.Fact + '<br>' + fact.Description + '</p>');
}
// Load and display the random added fact
loadRandomAddedFact();
</script>
</body>
</html>