eastbayeff

Untitled

Aug 28th, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { makeElement } from "./helpers.js";
  2.  
  3. document.querySelector('button').onclick = getWeather;
  4.  
  5. function getWeather(){
  6.     let location = document.getElementById('location').value;
  7.     fetch("https://hackingtonsapiproxy.herokuapp.com/" + "https://www.metaweather.com/api/location/search/?query=" + location)
  8.     .then(function(response){
  9.         if(response.ok){
  10.             return response.json()
  11.         }
  12.     }).then(function(data){
  13.         console.log(data)
  14.         showResults(data);
  15.     })
  16. }
  17.  
  18. function showResults(data){
  19.     let resultsContainer = makeElement('div', 'qcontainer')
  20.     let resultsText = makeElement('h2', undefined, data[0].title)
  21.     let url = makeElement('a', 'link', "https://metaweather.com/" + data[0].woeid)
  22.    
  23.  
  24.     resultsContainer.append(resultsText, url)
  25.     document.body.appendChild(resultsContainer)
  26.  
  27. }
  28.  
  29. function weatherResults(title, index, data){
  30.     let resultsContainer = makeElement('div', 'qcontainer')
  31.     let resultsText = makeElement('h2', undefined, title.title)
  32.     let url = makeElement('a', 'link', "https://metaweather.com/" + data)
  33.    
  34.  
  35.     resultsContainer.append(resultsText, url)
  36.     document.body.appendChild(resultsContainer)
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment