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

Evelyn #23

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
65b7a9a
learnings on July 23 2021
Jul 24, 2021
0e96e2f
learnings on July 26th, 2021
Jul 27, 2021
fe7b323
the dom
Jul 28, 2021
e4f10c1
chapter 6 finished learning
Jul 30, 2021
9a6d1e1
chapter 7 form & form events
Jul 30, 2021
69594b3
created a Ninja quiz
Jul 30, 2021
bf95c7a
practiced once
Jul 30, 2021
6cb9391
practice twice
Jul 30, 2021
2ce66ef
switching computer
Evelyn-ZYW Aug 30, 2021
3fb03a1
chapter 9 learnings
Evelyn-ZYW Aug 30, 2021
a217b0b
learnings of the mini project - todos
Evelyn-ZYW Aug 31, 2021
5132337
understanding Async in a very basic level
Evelyn-ZYW Sep 3, 2021
fe7c3eb
understanding HTTP request & JSON
Evelyn-ZYW Sep 3, 2021
d7aef64
understanding promises and how to use it in a request
Evelyn-ZYW Sep 3, 2021
5387bb0
chain promises together
Evelyn-ZYW Sep 3, 2021
933384b
understanding fetch() and async & await
Evelyn-ZYW Sep 4, 2021
e0acc1d
understanding throwing & catching errors
Evelyn-ZYW Sep 4, 2021
e0ee6fd
object shorthand notation
Evelyn-ZYW Sep 16, 2021
e5095a2
get reference of the card and details elements
Evelyn-ZYW Sep 16, 2021
1006f26
created updateUI function to receive the data from updateCity functio…
Evelyn-ZYW Sep 16, 2021
d6eedbc
destructuring - an easy way to get properties from an object and stor…
Evelyn-ZYW Sep 16, 2021
b9788f2
get references of the time and icon elements; added icons and imgs
Evelyn-ZYW Sep 16, 2021
7fe227c
use Ternary Operator instead of regular if elase statement
Evelyn-ZYW Sep 16, 2021
909dbfe
localStorage: 1. setItem 2. getItem 3. removeItem 4. clear
Evelyn-ZYW Sep 19, 2021
819ef71
localStorage for the weather app
Evelyn-ZYW Sep 19, 2021
2917f35
class inheritance
Evelyn-ZYW Sep 21, 2021
9f20336
constructor inheritance & super()
Evelyn-ZYW Sep 21, 2021
4fa64fb
prototype model
Evelyn-ZYW Sep 21, 2021
73bae52
prototypal inheritance
Evelyn-ZYW Sep 21, 2021
aa543a1
making a Forecast class for the weather app
Evelyn-ZYW Sep 21, 2021
c2c7415
firebase
Evelyn-ZYW Sep 22, 2021
cf00bfc
deleted node_modules folder
Evelyn-ZYW Sep 22, 2021
72355b6
real-time listeners enable real-time update to the UI when adding or …
Evelyn-ZYW Sep 22, 2021
317f8e4
unsubscribe from the collection changes
Evelyn-ZYW Sep 22, 2021
1430167
cleared some unused files and codes
Evelyn-ZYW Sep 22, 2021
cada1e3
real-time chatroom done
Evelyn-ZYW Oct 4, 2021
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
Prev Previous commit
Next Next commit
object shorthand notation
  • Loading branch information
Evelyn-ZYW committed Sep 16, 2021
commit e0ee6fde0c3dc9c3a75648ab829bda5272f1d0d4
47 changes: 47 additions & 0 deletions chapter_13_weather_app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!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" />
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles.css" />
<title>Weather App</title>
</head>
<body>

<div class="container my-5 mx-auto">

<h1 class="text-muted text-center my-4">NinjaWeather</h1>

<form class="change-location my-4 text-center text-muted">
<label for="city">Enter a location for weather information</label>
<input type="text" name="city" class="form-control p-4">
</form>

<div class="card shadow-lg rounded">
<img src="https://via.placeholder.com/400x300" class="time card-img-top" alt="">
<div class="icon bg-light mx-auto text-center">

</div>
<div class="text-muted text-uppercase text-center details">
<h5 class="my-3">City name</h5>
<div class="my-3">Weather Condition</div>
<div class="display-4 my-4">
<span>temp</span>
<span>&deg;C</span>
</div>
</div>
</div>

</div>

<script src="scripts/forecast.js"></script>
<script src="scripts/app.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions chapter_13_weather_app/sandbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
console.log(1)
console.log(2)

//This is asynchronous code in action. In this case we are not fetching data from a database, this is just wait in two seconds to emulate that request and then we are firing the console log.
setTimeout(()=>{
console.log('callback function fired')
}, 2000)

console.log(3)
console.log(4)
33 changes: 33 additions & 0 deletions chapter_13_weather_app/scripts/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//DOM manipulation in this document - show things on the page

const cityForm = document.querySelector('form');

const updateCity = async (city) => {

// console.log(city)

const cityDetails = await getCity(city);
const weather = await getWeather(cityDetails.Key);

// return {
// cityDetails: cityDetails,
// weather: weather
// }

//object shorthand notation - when we have a property name and a value that are exactly the same name.
return { cityDetails, weather }
}

cityForm.addEventListener('submit', e=>{
//prevent default action
e.preventDefault();

//get city value (user input)
const city = cityForm.city.value.trim();
cityForm.reset();

//update the ui with new city
updateCity(city)
.then(data => console.log(data))
.catch(err => console.log(err))
})
41 changes: 41 additions & 0 deletions chapter_13_weather_app/scripts/forecast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//this document contains all of the JavaScript that will be responsible for interacting with the weather API and getting data

// this is the end point to the accuWeather API
const key = 'RjKdmCGXOVfvKql2HIhD8aEGQkaKB2Bv';

//when we're requesting data from the end point to this API, we're going to have to do two different things:
//1. we need to make a request to a certain end point to get city information(a city code)
//2. use that city code to make a second request to a weather conditions API end point. We're going to send that city code to it so it can identify where we want to get the weather and it will send us the weather conditions back for that area.

//get weather information
const getWeather = async (id) => {
const base = 'http://dataservice.accuweather.com/currentconditions/v1/';
const query = `${id}?apikey=${key}`;

const response = await fetch(base + query);
const data = await response.json();

// console.log(data)
return data;
}

//get city information
const getCity = async (city) => {
const base = 'http://dataservice.accuweather.com/locations/v1/cities/search';
const query = `?apikey=${key}&q=${city}`;

const response = await fetch(base + query);
const data = await response.json();

// console.log(data)
return data[1];
}

//
getCity('richmond')
.then(data => {
//we want to take the data and get the Key(city code), and pass it into a get weather request - getWeather(). We return a promise by returning the whole thing, so we can chain these things together.
return getWeather(data.Key)})
.then(data => {
console.log(data)})
.catch(err => console.log(err))
8 changes: 8 additions & 0 deletions chapter_13_weather_app/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body{
background: #eeedec;
letter-spacing: 0.2em;
font-size: 0.8em;
}
.container{
max-width: 400px;
}