Skip to content

Commit

Permalink
template code
Browse files Browse the repository at this point in the history
  • Loading branch information
schen9981 committed Sep 3, 2020
0 parents commit 1eaee6e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var corsApiUrl = 'https://cors-anywhere.herokuapp.com/';
// TODO: REPLACE YOUR TOKEN
var apiToken = '?token=ZAWafueiwitra0tTaAR2QzY3054rfHOgvv47pBG8Dug';

// fetches the data from the API endpoint
const doCORSRequest = (options) => {
var x = new XMLHttpRequest();
x.open("GET", corsApiUrl + options.url);
x.send(options.data);
return x;
}

// creates the promise
const corsPromise = () => new Promise((resolve, reject) => {
const request = doCORSRequest({ url: "https://trefle.io/api/v1/plants" + apiToken });
resolve(request);
})

//// TODO: ADD WHATEVER FUN CONTENT YOU WANT ////

// THIS IS SOME SAMPLE CODE FOR HOW TO USE PROMISES -- feel free to adapt this into a function!
corsPromise().then(request => request.onload = request.onerror = function () {
// TODO: ADD FUNCTION, ETC. FOR WHATEVER YOU WANT TO DO ONCE THE DATA IS RECEIVED
});
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>CS1300 JavaScript Studio</title>
<!-- <script src="https://unpkg.com/axios/dist/axios.min.js"></script> -->
<link rel="stylesheet" href="styles.css">
</head>

<body>
<!-- TODO: ADD HTML FOR WHATEVER YOU WANT TO SHOW ON THE PAGE! -->
</body>
<script src="app.js"></script>

</html>
Empty file added styles.css
Empty file.

0 comments on commit 1eaee6e

Please sign in to comment.