diff options
-rw-r--r-- | fetch-MSFT-stockprice-API-request-react.js | 41 | ||||
-rw-r--r-- | mymodule.js | 2 | ||||
-rw-r--r-- | scratch.js | 11 | ||||
-rw-r--r-- | scratch2.js | 0 |
4 files changed, 54 insertions, 0 deletions
diff --git a/fetch-MSFT-stockprice-API-request-react.js b/fetch-MSFT-stockprice-API-request-react.js new file mode 100644 index 0000000..1df838f --- /dev/null +++ b/fetch-MSFT-stockprice-API-request-react.js @@ -0,0 +1,41 @@ +import React from 'react'; +import logo from './logo.svg'; +import './App.css'; + +const axios = require('axios'); + +class App extends React.Component { + constructor(props) { + super(props); + this.state = { status: 'LOADING' }; + } + + componentDidMount() { + const symbol = this.props.symbol; + const url = `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${symbol}&apikey=demo`; + + axios.get(url). + then(res => this.setState({ + error: null, + status: 'DONE', + price: res.data['Global Quote']['05. price'] + })). + catch(err => this.setState({ + error: err.message, + status: 'ERROR', + price: 'N/A' + })); + } + + render() { + if (this.state.status === 'ERROR') { + return (<h1>Error: {this.state.error}</h1>); + } else if (this.state.status === 'DONE') { + return (<h1>Price: {this.state.price}</h1>); + } else { + return (<h1>Loading...</h1>); + } + } +} + +export default App; diff --git a/mymodule.js b/mymodule.js new file mode 100644 index 0000000..93edce4 --- /dev/null +++ b/mymodule.js @@ -0,0 +1,2 @@ + +exports.getName = () => "Kyle"
\ No newline at end of file @@ -74,3 +74,14 @@ String.prototype.format = function() { console.log('Is that a %s or a %s?... No, it\'s %s!'.format('plane', 'bird', 'SOman')); console.log((function(){}).constructor); + + +fetch('https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=demo').then(res => { + return res.json(); +}).then(price => console.log(price)); + + +const { getName } = require('./mymodule'); +console.log(getName()); + +console.log("ayy lmao".toUpperCase()); diff --git a/scratch2.js b/scratch2.js new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/scratch2.js |