Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { makeElement } from "./helpers.js";
- document.querySelector('button').onclick = getWeather;
- function getWeather(){
- let location = document.getElementById('location').value;
- fetch("https://hackingtonsapiproxy.herokuapp.com/" + "https://www.metaweather.com/api/location/search/?query=" + location)
- .then(function(response){
- if(response.ok){
- return response.json()
- }
- }).then(function(data){
- console.log(data)
- showResults(data);
- })
- }
- function showResults(data){
- let resultsContainer = makeElement('div', 'qcontainer')
- let resultsText = makeElement('h2', undefined, data[0].title)
- // let url = makeElement('a', 'link', "https://metaweather.com/" + data[0].woeid)
- let link = document.createElement("a");
- link.src="https://metaweather.com/" + data[0].woeid;
- resultsContainer.append(resultsText)
- resultsContainer.append(link)
- document.body.appendChild(resultsContainer)
- }
- function weatherResults(title, index, data){
- let resultsContainer = makeElement('div', 'qcontainer')
- let resultsText = makeElement('h2', undefined, title.title)
- let url = makeElement('a', 'link', "https://metaweather.com/" + data)
- resultsContainer.append(resultsText, url)
- document.body.appendChild(resultsContainer)
- }
Advertisement
Add Comment
Please, Sign In to add comment