Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
69 lines (65 loc) · 1.8 KB
/
Copy pathindex.html
File metadata and controls
69 lines (65 loc) · 1.8 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>U.S. Recession Indicator</title>
<style>
body {
font-family: sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background: #f0f0f0;
}
h1 {
margin-bottom: 10px;
}
#status {
font-size: 4em;
font-weight: bold;
padding: 20px;
border-radius: 10px;
}
.yes {
color: #fff;
background-color: #d32f2f;
}
.no {
color: #fff;
background-color: #388e3c;
}
</style>
</head>
<body>
<h1>Is the U.S. in a Recession?</h1>
<div id="status">Loading...</div>
<script>
async function fetchRecessionStatus() {
const apiUrl = 'https://corsproxy.io/?https://api.stlouisfed.org/fred/series/observations?series_id=USREC&api_key=0754382cf5d2972dfc8d39b5a1d383fd&file_type=json';
try {
const res = await fetch(apiUrl);
const data = await res.json();
const last = data.observations.reverse().find(o => o.value === "0" || o.value === "1");
const status = document.getElementById('status');
if (last?.value === "1") {
status.textContent = "YES";
status.className = "yes";
} else if (last?.value === "0") {
status.textContent = "NO";
status.className = "no";
} else {
status.textContent = "Unknown";
}
} catch (err) {
document.getElementById('status').textContent = "Error fetching data";
console.error(err);
}
}
fetchRecessionStatus();
</script>
</body>
</html>