Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
Binary file removed assets/all-features.png
Binary file not shown.
Binary file removed assets/landing.png
Binary file not shown.
Binary file removed assets/multiple-searches.png
Binary file not shown.
Binary file removed assets/single-search.png
Binary file not shown.
68 changes: 68 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./styles.css"/>
<script defer src="./main.js"></script>
</head>
<body>
<header class="header">
<h1>Weather App</h1>
<form id="location">
<label for="location">Pick a Location</label>
<input id="inputText"type="text" name="location" value=""/>
<input id="submitLocation" type="submit" value="Get Weather" />
</form>
</header>
<aside class="temp-conversion">
<form id="conversionForm">
<strong><label for="temp-to-convert">Convert the Temperature:</label></strong>
<br>
<br>
<input type="number" name="convert" id="temp-to-convert" />
<br>
<br>
<input type="radio" name="conv" value="C" id="to-c" />
<label>Celsius</label>
<br>
<input type="radio" name="conv" value="F" id="to-f" />
<label>Fahrenheit</label>
<br>
<br>
<input type="submit" value="submit" />
<h4 id="result"></h4>
</form>
</aside>
<main class="main">
<div class="main">
<img src="" alt="">
<article>
Choose a location to view the weather.
</article>

<ul></ul>
<ul></ul>
<ul></ul>
<ul></ul>
<aside class="weatherForecast">
<h2></h2>
<h2></h2>
<h2></h2>
<article></article>
<article></article>
<article></article>
</aside>
</main>
<aside class="previous">
<section>
<h4>Previous Searches</h4>
<ul>
<p>No previous searches.</p>
</ul>
</section>
</aside>
</body>
</html>
78 changes: 78 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const article = document.querySelectorAll("article")
const ul = document.querySelectorAll( "ul")
const h2 = document.querySelector("bold")
const aside = document.querySelectorAll("aside")
const p = document.querySelector("p")
const array = []
const image = document.querySelector("img")
document.querySelector("form").addEventListener("submit", (event) => {
event.preventDefault()
fetch(`https://wttr.in/${event.target.location.value}?format=j1`)
.then(result => {
return result.json()
}).then(weather => {
console.log(weather)
function chance(){
if(weather.weather[0].hourly[0].chanceofsunshine > 50){
image.setAttribute("src", "./assets/icons8-summer.gif")
image.setAttribute("alt", "sun")
} else if (weather.weather[0].hourly[0].chanceofrain > 50){
image.setAttribute("src", "./assets/icons8-torrential-rain.gif")
image.setAttribute("alt", "rain")
} else if (weather.weather[0].hourly[0].chanceofsnow > 50){
image.setAttribute("src", "./assets/icons8-light-snow.gif")
image.setAttribute("alt", "snow")
}
}
function get(){
let input = document.getElementById('inputText')
if(input.value.toLowerCase() === weather.nearest_area[0].areaName[0].value.toLowerCase()){
article[0].innerHTML = `<h2>${weather.nearest_area[0].areaName[0].value}<h2>`
chance()
article[0].innerHTML += `<p><strong>Area</strong>: ${weather.nearest_area[0].areaName[0].value}</p>`

} else {
article[0].innerHTML = `<h2>${input.value}<h2>`
chance()
article[0].innerHTML += `<p><strong>Nearest Area</strong>: ${weather.nearest_area[0].areaName[0].value}</p>`

}
input.value = "";
article[0].innerHTML += `<p><strong>Region</strong>: ${weather.nearest_area[0].region[0].value}</p><p><strong>Country</strong>: ${weather.nearest_area[0].country[0].value}</p><p><strong>Currently</strong>: Feels like ${weather.current_condition[0].FeelsLikeF}°F </p>`
article[0].innerHTML += `<p><strong>Chance of Sunshine</strong>: ${weather.weather[0].hourly[0].chanceofsunshine}</p><p><strong>Chance of Rain</strong>: ${weather.weather[0].hourly[0].chanceofrain}</p><p><strong>Chance of Snow</strong>: ${weather.weather[0].hourly[0].chanceofsnow}</p>`
const head = document.querySelectorAll('h2')
head[2].innerHTML = `<strong>Today</strong>`
head[3].innerHTML = `<strong>Tomorrow</strong>`
head[4].innerHTML = `<strong>Day After Tomorrow</strong>`
article[1].innerHTML = `<strong>Average Temperature</strong>: ${weather.weather[0].avgtempF}°F<br><br><strong>Max Temperature</strong>: ${weather.weather[0].maxtempF}°F<br><br><strong>Min Temperature</strong>: ${weather.weather[0].mintempF}°F`
article[2].innerHTML = `<strong>Average Temperature</strong>: ${weather.weather[1].avgtempF}°F<br><br><strong>Max Temperature</strong>: ${weather.weather[1].maxtempF}°F<br><br><strong>Min Temperature</strong>: ${weather.weather[1].mintempF}°F`
article[3].innerHTML = `<strong>Average Temperature</strong>: ${weather.weather[2].avgtempF}°F<br><br><strong>Max Temperature</strong>: ${weather.weather[2].maxtempF}°F<br><br><strong>Min Temperature</strong>: ${weather.weather[2].mintempF}°F`
}
get()
let li = document.createElement('li')
if(!array.includes(weather.nearest_area[0].areaName[0].value)){
li.innerHTML = `<a href="">${weather.nearest_area[0].areaName[0].value}</a>:${weather.current_condition[0].FeelsLikeF}°F`
ul[4].append(li)
}
p.remove()
array.push(weather.nearest_area[0].areaName[0].value)
li.addEventListener("click", (event) => {
event.preventDefault()
get()
})
const conversion = document.querySelector('#conversionForm');
conversion.addEventListener('submit', (event) => {
event.preventDefault();
let conversion = event.target.convert.value;
let toC = document.querySelector('#to-c')
let toF = document.querySelector('#to-f')
if (toC.checked) {
conversion = (conversion - 32) * (5 / 9);
document.querySelector('#result').innerHTML = `${conversion.toFixed(2)}°C`;
} else {
conversion = conversion * (9 / 5) + 32;
document.querySelector('#result').innerHTML = `${conversion.toFixed(2)}°F`;
}
});
})
});
49 changes: 49 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.header {
background-color: rgb(9, 67, 67);
grid-area: header;
text-align: center;
}

.main {
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
justify-content: center;
background-color: rgb(54, 146, 106);
text-align: center;
grid-area: main;
border-top: 2px solid rgb(208, 232, 128);
border-left: 2px solid rgb(208, 232, 128);
border-bottom: 2px solid rgb(208, 232, 128);
border-right: 2px solid rgb(208, 232, 128);
}

.previous {
background-color: rgb(208, 232, 128);
display: grid;
grid-area: previous;
text-decoration: underline;
}

.conversion {
background-color: rgb(118, 155, 95);
display: grid;
grid-area: aside;
}
.weatherForecast {
background-color: rgba(197, 231, 153, 0.543);
display: grid;
grid-template-columns: "auto auto auto";
grid-template-rows: "auto auto auto";
grid-template-areas: "header header header";
border-left: thick solid rgb(208, 232, 128);
border-right: thick solid rgb(208, 232, 128);
border: 50px;

}
body {
background-color: rgb(174, 239, 151);
display: grid;
text-align: center;
grid-template-columns: "auto auto auto";
grid-template-rows: "auto auto auto";
grid-template-areas: "header header header" "aside main previous";
}