diff --git a/Practice/APIs/index.html b/Practice/APIs/index.html new file mode 100644 index 0000000..60a6fc5 --- /dev/null +++ b/Practice/APIs/index.html @@ -0,0 +1,97 @@ + + + + + + Pokémon Info + + + + + +

+ + +

Possible pokemon names

+ + + + \ No newline at end of file diff --git a/Practice/APIs/script.js b/Practice/APIs/script.js new file mode 100644 index 0000000..1b8a400 --- /dev/null +++ b/Practice/APIs/script.js @@ -0,0 +1,46 @@ +//Accessing API with fetch function + +fetch("https://pokeapi.co/api/v2/pokemon/pikachu") +.then(response =>{ + if(!response.ok){ + throw new Error("Not a pokemon!"); + } + return response.json(); +}) +.then(data => console.log(data.weight)) +.catch(error => console.error(error)); + +//Accessing API with async/await function + +fetchData(); + +async function fetchData(){ + try{ + const response = await fetch("https://pokeapi.co/api/v2/pokemon/pikachu"); + if(!response.ok){ + throw new Error("Not a pokemon!"); + } + const data = await response.json(); + console.log(data); + } + catch(error){ + console.error(error); + } +} + +//FOR THE PAGE + +async function pokemonapi(){ + const name = document.getElementById("pokemon").value.toLocaleLowerCase() + try { + const response = await fetch("https://pokeapi.co/api/v2/pokemon/" + name); + if(!response.ok){ + throw new Error("Not a pokemon!"); + } + const data = await response.json(); + document.getElementById("pokemonweight").innerText = "The weight of the pokemon is " + data.weight; + document.getElementById("pokeimage").src = data.sprites.front_default; + } catch (error) { + console.error(error); + } +} \ No newline at end of file diff --git a/Practice/Json/Index.html b/Practice/Json/Index.html new file mode 100644 index 0000000..a03a791 --- /dev/null +++ b/Practice/Json/Index.html @@ -0,0 +1,12 @@ + + + + + + Document + + + + + + \ No newline at end of file diff --git a/Practice/Json/names.json b/Practice/Json/names.json new file mode 100644 index 0000000..618e103 --- /dev/null +++ b/Practice/Json/names.json @@ -0,0 +1 @@ +["Spongebob", "Patrick", "Sandy", "Squidward"] \ No newline at end of file diff --git a/Practice/Json/people.json b/Practice/Json/people.json new file mode 100644 index 0000000..2506eef --- /dev/null +++ b/Practice/Json/people.json @@ -0,0 +1,17 @@ +[{ + "name": "Spongebob", + "age": 50, + "isemployed": true +}, { + "name": "Patrick", + "age": 32, + "isemployed": true +}, { + "name": "Sandy", + "age": 32, + "isemployed": false +}, { + "name": "Squidward", + "age": 32, + "isemployed": false +}] \ No newline at end of file diff --git a/Practice/Json/person.json b/Practice/Json/person.json new file mode 100644 index 0000000..ac20cbb --- /dev/null +++ b/Practice/Json/person.json @@ -0,0 +1,10 @@ +{ + "name": "Spongebob", + "age": 50, + "isemployed": true, + "Hobbies": ["Karate", "Danceing", "Cooking"], + "address": { + "street": "Some st", + "number": 123 + } +} \ No newline at end of file diff --git a/Practice/Json/script.js b/Practice/Json/script.js new file mode 100644 index 0000000..930d1a8 --- /dev/null +++ b/Practice/Json/script.js @@ -0,0 +1,19 @@ +const names = ["Spongebob", "Patrick", "Sandy", "Squidward"]; + +const jsonstrings = JSON.stringify(names); +console.log(names); +console.log(jsonstrings); + +const person = { + name: "Spongebob", + age: 50, + isemployed: true, + Hobbies: ["Karate", "Danceing", "Cooking"], + address: { + street: "Some st", + number: 123 + } +}; + +console.log(person); +console.log(JSON.stringify(person)); \ No newline at end of file