Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <meta http-equiv="x-ua-compatible" content="ie=edge" />
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- <title>Bitcoin Price</title>
- </head>
- <style>
- html,
- body {
- height: 100%;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- text-align: center;
- }
- h1 {
- font-size: 50px;
- margin-block-start: 0;
- margin-block-end: 0;
- }
- p {
- margin-block-start: 0;
- margin-block-end: 0;
- }
- .price {
- font-size: 80px;
- margin: 50px 0;
- }
- </style>
- <body>
- <article>
- <h1>Bitcoin</h1>
- <p class="price"></p>
- <p class="last-update"></p>
- </article>
- <script>
- var DOLLAR = "$";
- var LAST_UPDATE = "Last update: ";
- var price = document.querySelector(".price");
- var lastUpdate = document.querySelector(".last-update");
- function newPrice(res) {
- price.textContent =
- JSON.parse(res.target.response).bitcoin.usd.toLocaleString() + DOLLAR;
- lastUpdate.textContent =
- LAST_UPDATE + new Date().toLocaleString("de-de");
- }
- function requestPrice() {
- var fetchPrice = new XMLHttpRequest();
- fetchPrice.addEventListener("load", newPrice);
- fetchPrice.open(
- "GET",
- "https://api.coingecko.com/api/v3/simple/price?vs_currencies=usd&ids=bitcoin"
- );
- fetchPrice.send();
- }
- requestPrice();
- setInterval(function () {
- requestPrice();
- }, /*30000*/ 120000);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement