Skip to content

Instantly share code, notes, and snippets.

@ProfAndreaPollini
Created October 27, 2020 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ProfAndreaPollini/6bb700d3f7525f04a1f833af39b195d7 to your computer and use it in GitHub Desktop.
Save ProfAndreaPollini/6bb700d3f7525f04a1f833af39b195d7 to your computer and use it in GitHub Desktop.
motivapp
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()
<!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