Created
October 27, 2020 12:50
-
-
Save ProfAndreaPollini/6bb700d3f7525f04a1f833af39b195d7 to your computer and use it in GitHub Desktop.
motivapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("it works"); | |
let data = []; | |
let authors = []; | |
/* | |
fetch("https://type.fit/api/quotes") | |
.then(r => r.json()) | |
.then(body => { | |
console.log(body) | |
data = body; | |
}) | |
.then(()=>{ | |
console.log(data) | |
}) | |
.catch(err => console.log(err)) | |
console.log(data)*/ | |
const authorsDiv = document.getElementById("authors") | |
async function main() { | |
data = await fetch("https://type.fit/api/quotes").then(r => r.json()) | |
let authors = data.map(x => {return x.author}) // recupero solo i nomi degli autori | |
authors = new Set(authors) // creo il set | |
authors = [...authors] //costruisco una lista partendo dal contenuto del set | |
authors = authors.sort() // in ordine alfabetico | |
authors.forEach(name => { | |
const authorDiv = document.createElement("div") // creo un nuovo div | |
authorDiv.innerHTML = name //setto il contenuto del div | |
authorsDiv.appendChild(authorDiv) //lo aggingo alla lista degli autori | |
}) | |
console.log(authors) | |
} | |
main() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<div id="authors"> | |
</div> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment