Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39f1817

Browse files
committed
Week7 json and fetch
1 parent f828588 commit 39f1817

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Exercises
2+
3+
## Exercise 1
4+
5+
Imagine your are running a meal ordering website.
6+
Orders come in from the web and we need to store them in a json file.
7+
Create a json file with two orders that contain at least these things:
8+
9+
- Order name
10+
- Order id
11+
- Price
12+
- List of drinks with the order
13+
- Order extras (fx cheese, lettuce etc.)
14+
15+
## Exercise 2
16+
1. Go through [planets.json](https://raw.githubusercontent.com/dariusk/corpora/master/data/science/planets.json) and explain the data structure.
17+
18+
19+
1. Using the `planets` variable `console.log` jupiters last moon.
20+
21+
```
22+
const planetsJson = '{"description": "Planets (including dwarf planets as recognized by the IAU) that orbit the Sun, with their natural satellites.","planets": [{"name": "Mercury","moons": []},{"name": "Venus","moons": []},{"name": "Earth","moons": ["Moon"]},{"name": "Mars","moons": ["Deimos","Phobos"]},{"name": "Ceres","moons": []},{"name": "Jupiter","moons": ["Metis","Adrastea","Amalthea","Thebe","Io","Europa","Ganymede","Callisto","Themisto","Leda","Himalia","Lysithea","Elara","S/2000 J11","S/2003 J12","Carpo","Euporie","S/2003 J3","S/2003 J18","Orthosie","Euanthe","Harpalyke","Praxidike","Thyone","S/2003 J16","Iocaste","Mneme","Hermippe","Thelxinoe","Helike","Ananke","S/2003 J15","Eurydome","Arche","Herse","Pasithee","S/2003 J10","Chaldene","Isonoe","Erinome","Kale","Aitne","Taygete","S/2003 J9","Carme","Sponde","Megaclite","S/2003 J5","S/2003 J19","S/2003 J23","Kalyke","Kore","Pasiphae","Eukelade","S/2003 J4","Sinope","Hegemone","Aoede","Kallichore","Autonoe","Callirrhoe","Cyllene","S/2003 J2"]},{"name": "Saturn","moons": ["Tarqeq","Pan","Daphnis","Atlas","Prometheus","Pandora","Epimetheus","Janus","Aegaeon","Mimas","Methone","Anthe","Pallene","Enceladus","Tethys","Calypso","Telesto","Polydeuces","Dione","Helene","Rhea","Titan","Hyperion","Iapetus","Kiviuq","Ijiraq","Phoebe","Paaliaq","Skathi","Albiorix","S/2007 S2","Bebhionn","Erriapo","Siarnaq","Skoll","Tarvos","Greip","S/2004 S13","Hyrrokkin","Mundilfari","S/2006 S1","Jarnsaxa","Narvi","Bergelmir","S/2004 S17","Suttungr","Hati","S/2004 S12","Bestla","Farbauti","Thrymr","S/2007 S3","Aegir","S/2004 S7","S/2006 S3","Kari","Fenrir","Surtur","Ymir","Loge","Fornjot"]},{"name": "Uranus","moons": ["Cordelia","Ophelia","Bianca","Cressida","Desdemona","Juliet","Portia","Rosalind","Cupid","Belinda","Perdita","Puck","Mab","Miranda","Ariel","Umbriel","Titania","Oberon","Francisco","Caliban","Stephano","Trinculo","Sycorax","Margaret","Prospero","Setebos","Ferdinand"]},{"name": "Neptune","moons": ["Naiad","Thalassa","Despina","Galatea","Larissa","Proteus","Triton","Nereid","Halimede","Sao","Laomedeia","Psamathe","Neso"]},{"name": "Pluto","moons": ["Charon","Styx","Nix","Kerberos","Hydra"]},{"name": "Haumea","moons": ["Namaka","Hiiaka"]},{"name": "Makemake","moons": []},{"name": "Eris","moons": ["Dysnomia"]}]}';
23+
24+
const planets = JSON.parse(planetsJson);
25+
```
26+
27+
28+
## Exercise 3
29+
Use [this api](http://api.open-notify.org/astros.json) to fetch how many astronauts are currently in spaces.
30+
31+
`console.log` the following using the data you get from the api:
32+
33+
```
34+
There are NUMBER_OF_ASTRONAUTS in space they are:
35+
36+
ASTRONAUT_NAME1
37+
38+
ASTRONAUT_NAME2
39+
40+
ASTRONAUT_NAME3
41+
42+
ASTRONAUT_NAME4
43+
44+
ASTRONAUT_NAME5
45+
46+
Etc...
47+
48+
```
49+
50+
## Exercise 4
51+
Using this api: https://thecatapi.com/
52+
1. Find some information about cats that have the breed siberian.
53+
1. Display 3 siberian cats.
54+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
JSON
3+
4+
JSON stands for JavaScript Object Notation
5+
6+
JSON is a lightweight format for storing and transporting data
7+
8+
JSON is often used when data is sent from a server to a web page
9+
10+
Typical example of json: https://jsonplaceholder.typicode.com/users
11+
https://jsonlint.com/
12+
13+
JSON names require double quotes.
14+
15+
In JSON, values must be one of the following data types:
16+
17+
a string
18+
a number
19+
an object (JSON object)
20+
an array
21+
a boolean
22+
null
23+
24+
*/
25+
26+
/*
27+
28+
FETCH
29+
30+
Uses ajax technology: load data quickly and asynchronously, or in the background without delaying page rendering.
31+
32+
*/
33+

0 commit comments

Comments
 (0)