Last active
May 6, 2023 22:54
-
-
Save ryqndev/493bb266f5c2238760cfeabd308c0724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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.0"> | |
<title>Document</title> | |
<script src="./script.js"></script> | |
</head> | |
<body> | |
<input type="text" id="user-input" /> | |
<button onclick="clicked()">click me</button> | |
<div id="display"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let POLYGON_API = 'replace-this-with-your-api'; | |
function clicked() { | |
// gets the user typed value | |
let userStock = document.getElementById('user-input').value; | |
// fetches data from the api | |
fetch( | |
'https://api.polygon.io/v2/aggs/ticker/' + userStock + '/range/1/day/2023-01-09/2023-01-09?apiKey=' + POLYGON_API, | |
) | |
.then(response => response.json()) | |
.then(response => { | |
// prints out the response | |
console.log(response); | |
// sets the value in the website to be stock value | |
document.getElementById('display').innerHTML = response['results'][0]['c']; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment