Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final edit #16

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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": 5502
}
49 changes: 49 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<title>Weather App</title>
<link rel="stylesheet" href="./style.css"/>
<script defer src="weather.js"></script>
</head>
<body>
<header>
<h1>Weather App</h1>
<!-- <a href="https://wttr.in/">wttr.in</a> -->
<form>
<label>Pick a location</label>
<input id="location" name="-search-bar" type="text" required/>
<button type="submit">Get Weather</button>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be of input type=submit in order to pass the tests

</form>
</header>
<aside></aside>
<main id="current" class="current">
<article id="location-info">

</article>
<aside class="forecast">
<article id="one">
<h4 id="today"></h3>
<br>
</article>
<article id="two">
<h4 id="tomorrow"></h4>
<br>
</article>
<article id="three">
<h4 id="day-after-tomorrow"></h4>
<br>
</article>
</aside>
</main>
<aside class="side-bar">
<section></section>
<h4>Previous Searches</h4>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be inside section

Also it is missing the "No previous searches" text

<ul class="previous-searches"> </ul>
</aside>



</body>
</html>

79 changes: 79 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
header {
background-color: rgb(104, 241, 216);
text-align: center;
box-sizing: border-box;
border-style: solid;
border-color: black;
height: 200px;
width: 75%;
margin: 10px auto;



}
h1 {
/* padding-top: 20px; */
font-size: 60px;
}

form {
font-size: 25px;
}
form input {
height: 25px;
width: 180px;
}
form button {
height:30px;
width: 125px;
font-size: 15px;

}
main {
display: grid;
block-size: fit-content;
position: fixed;
background-color: rgb(244, 245, 237);
box-sizing: border-box;
margin-left: 15%;
min-height: 100px;
max-height: 50%;
width: 50%;
font-size: 25px;
text-align: center;
border: 1px solid rgb(104, 241, 216);

}
.previous-searches link {
list-style-type: circle;
}
/* main article {
padding-top: 15px;
} */

.side-bar {

box-sizing: border-box;
font-size: 25px;
text-align: right;
margin: 10px 200px;


}
.heading {
font-size: 50px;
font-weight: bold;
}
.forecast {
display: grid;
position: fixed;
bottom: 0px;
width: auto;
grid-template-columns: repeat(3, 250px);
grid-auto-rows: minmax(100px, auto);
margin: 100px 100px;
}




119 changes: 119 additions & 0 deletions weather.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
const BASE_URL = "https://wttr.in"
const form = document.querySelector("form");
const sidebar = document.querySelector(".side-bar")
const userInput = document.querySelector("input")
const main = document.querySelector("main");
const todayArticle = document.querySelector("#one");
const tomorrowArticle = document.querySelector("#two");
const dayAfterArticle = document.querySelector("#three")
const current = document.querySelector("#current #location-info")
const heading = document.createElement("h2");
current.innerHTML = "Choose a location to view the weather."
const previousSearches = document.querySelector(".previous-searches")
const ul = document.querySelector(".previous-searches")
const getToday = document.querySelector("#today");
const getTomorrow = document.querySelector("#tomorrow");
const getDayAfter = document.querySelector("#day-after-tomorrow")

form.addEventListener("submit", (event)=> {
event.preventDefault();
const location = userInput.value


// heading.textContent = label

getWeatherByLocation(location);




form.reset();
})



function getWeatherByLocation(location) {

fetch(`${BASE_URL}/${location}?format=j1`)
.then((response) =>

response.json()

)
.then((location) => {
// const heading = document.querySelector(h2);
const p = document.createElement("p");
p.setAttribute("class", "heading")
const p1 = document.createElement("p");
const p2 = document.createElement("p");
const p3 = document.createElement("p");
const p4 = document.createElement("p");

const areaName = location.nearest_area[0].areaName;
const region = location.nearest_area[0].region;
const country = location.nearest_area[0].country[0].value;
const feelsLike = location.current_condition[0].FeelsLikeF;

const today = location.weather[0];
const todayAverageTemp = today.avgtempF
const todayMaxTemp = today.maxtempF
const todayMinTemp = today.mintempF
const tomorrow = location.weather[1];
const tomorrowAverageTemp = tomorrow.avgtempF;
const tomorrowMaxTemp = tomorrow.maxtempF;
const tomorrowMinTemp = tomorrow.mintempF;
const dayAfter = location.weather[2];
const dayAfterAverageTemp = dayAfter.avgtempF;
const dayAfterMaxTemp = dayAfter.maxtempF;
const dayAfterMinTemp = dayAfter.mintempF;
todayArticle.append(`Average Temperature: ${todayAverageTemp}\u2109`);
todayArticle.append(`Max Temperature: ${todayMaxTemp}\u2109`);
todayArticle.append(`Min Temperature: ${todayMinTemp}\u2109`);
tomorrowArticle.append(`Average Temperature: ${tomorrowAverageTemp}\u2109`);
tomorrowArticle.append(`Max Temperature: ${tomorrowMaxTemp}\u2109`);
tomorrowArticle.append(`Min Temperature: ${tomorrowMinTemp}\u2109`);
dayAfterArticle.append(`Average Temperature: ${dayAfterAverageTemp}\u2109`);
dayAfterArticle.append(`Max Temperature: ${dayAfterMaxTemp}\u2109`);
dayAfterArticle.append(`Min Temperature: ${dayAfterMinTemp}\u2109`);
getToday.innerText = "Today";
getTomorrow.innerText = "Tomorrow"
getDayAfter.innerText = "Day After Tomorrow"






main.append(p);
p.append(`${areaName[0].value}`)
main.append(p1);
main.append(p2);
main.append(p3);
main.append(p4);
p1.append(`Area: ${areaName[0].value}`);
p2.append(`Region: ${region[0].value}`);
p3.append(`Country: ${country}`);
p4.append(`Currently: Feels Like ${feelsLike}\u2109`)/n;
const li = document.createElement('li')
ul.append(li)
const link = document.createElement("a");
link.setAttribute("href", `${BASE_URL}/${areaName[0].value}.htm`);
link.innerText = `${areaName[0].value} `;

li.innerText = feelsLike + "\u2109";

li.prepend(link);


console.log(location.current_condition[0].FeelsLikeF)

})


.catch((error) =>
console.log(error))
}