Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
92 changes: 92 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 1
const logPost = async function (postId) {
const postReq = await fetch("https://jsonplaceholder.typicode.com/posts/" + postId)
const json = await postReq.json()
const post = `
Title: ${json.title}
Post: ${json.body}
`
console.log(post)
}

// logPost(6)

// 2
const logUsers = async function () {
const usersReq = await fetch("https://jsonplaceholder.typicode.com/users/")
const json = await usersReq.json()
const users = json.map(
function (user) {
return user.name
}).join(", ")
console.log(users)
}

// logUsers()

// 3
const getBizUsers = async function () {
const usersReq = await fetch("https://jsonplaceholder.typicode.com/users/")
const json = await usersReq.json()
const bizUsers = json.filter(
function (user) {
return user.email.includes(".biz")
})
console.log(bizUsers)
}

// getBizUsers()

// 4
const longestPost = async function () {
const postReq = await fetch("https://jsonplaceholder.typicode.com/posts/")
const json = await postReq.json()
const postsSortedLength = json.sort(
function (a, b) {
return b.body.length - a.body.length
})
console.log(postsSortedLength[1].body.length)
}

// longestPost()

//5
const getCompletedTasks = async function () {
const todoReq = await fetch("https://jsonplaceholder.typicode.com/todos")
const json = await todoReq.json()
const completedTasks = json.filter(
function (task) {
return task.completed
})
console.log(completedTasks)
}

// getCompletedTasks()

//6
const displayPhotos = async function () {
const photosReq = await fetch("https://jsonplaceholder.typicode.com/photos")
const json = await photosReq.json()

let photos = json.slice(0, 9)
document.body.innerHTML = photos.map(function (photo) {
return `<img src="${photo.url}" alt="${photo.title}">`
}).join("")
}

// displayPhotos()

//7
const findClosest = async function () {
const usersReq = await fetch("https://jsonplaceholder.typicode.com/users/")
const json = await usersReq.json()

const userByProximity = json.sort(
function (a, b) {
return proximity(a) - proximity(b)
})
}

function proximity(user) {
const myLocation = navigator.geolocation.getCurrentPosition((user) => {})
}
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Code Fluency</title>
</head>

<body>
<script type="text/javascript" src="app.js"></script>
</body>

</html>