Skip to content

Instantly share code, notes, and snippets.

@sjehutch
Created May 20, 2018 17:42
Show Gist options
  • Save sjehutch/4aafe0757e496e8c53ba764377d9d0f1 to your computer and use it in GitHub Desktop.
Save sjehutch/4aafe0757e496e8c53ba764377d9d0f1 to your computer and use it in GitHub Desktop.
bitcoin price USD
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div id="option1">Bitcoin Price
<br>
</div>
<div id="option2"></div>
<script>
var output1 = document.getElementById("option1");
var output2 = document.getElementById("option2");
//output1.innerHTML="test";
var xhr = new XMLHttpRequest ();
var url = "https://api.coindesk.com/v1/bpi/currentprice.json";
xhr.onreadystatechange = function () {
var myObj = JSON.parse(xhr.responseText);
console.log(myObj);
output1.innerHTML="Bitcoin Price USD<br>"+myObj.bpi.USD.rate_float;
}
xhr.open("GET",url,true);
xhr.send();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment