diff --git a/README.md b/README.md index a9a4cc6..7c199aa 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,4 @@ I completed the challenge: 5 I feel good about my code: 4 I'm not sure if my constructors are setup cleanly... ``` +simple-api img beer diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..e0cc692 --- /dev/null +++ b/css/styles.css @@ -0,0 +1,42 @@ +*{ + box-sizing: border-box; +} + +body{ + text-align: center; +} + +html{ + background-image: url(https://www.angryotterliquor.crs/wcm/connect/sites/e51bd1e2-842b-4d42-80ff-ad13697a89f8/smartphone/Oktoberfest+Hero?MOD=AJPERES&CACHEID=ROOTWORKSPACE.Z18_2IKA1G82M08S50ANCIK0482G01-e51bd1e2-842b-4d42-80ff-ad13697a89f8-smartphone-p8g-GVW); + background-repeat: no-repeat; + background-size: cover; +} + +h1{ + color: rgb(53, 47, 47); + font-size: 5.5rem; + text-align: center; + background: rgba(250, 250, 250, 0.5); +} + +#container{ + text-align: center; +} + +#data{ + text-align: center; + font-size: 1.5rem; + color: white; + /* color: rgb(53, 47, 47); */ + padding-top: 3%; + /* background: rgba(250, 250, 250, 0.5); */ +} + +#beer{ + font-size: 2.5rem; +} + +img{ + width: 200px; + height: auto; +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..0fcc32e --- /dev/null +++ b/index.html @@ -0,0 +1,35 @@ + + + + + + Beer + + + +

Virtual Oktoberfest: Choose Your Beer

+ + +
+ +
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..bef769b --- /dev/null +++ b/js/main.js @@ -0,0 +1,42 @@ + +// Goal: Enable user to enter a futurama character and return the character's info. + +// get text info by user +// listen for click +// grab information (beer name) +// setup the url from the beer api +// perform the fetch request +// extract character description from the response +// display it in the DOM + +const beer = document.getElementById('beer') +let beerdata; + +const requestOptions = { + method: "GET", + redirect: "follow" +}; + +fetch("https://api.sampleapis.com/beers/ale", requestOptions) + .then((response) => response.json()) + .then((data) => { + console.log(data); + beerdata = data + }) + .catch((error) => console.error(error)); + +beer.addEventListener(("change"), () => { + // take the beer data use the filter function to get all matching results. The match function takes the name of the beer from the data (user's selected beer choice) + const beers = beerdata.filter(w => w.name.includes(beer.value)) + // solve the image issue by getting a random beer image + const randomBeer = beers[Math.floor (Math.random ()*beers.length)] + console.log(randomBeer); + const dataDiv = document.querySelector('#data') + dataDiv.innerText = randomBeer.price + const img = document.querySelector("img"); + img.src = randomBeer.image +}) + +// make a note that not all of the images exist in the API + +// completed with the help of Mentor, Michael Kazin.