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
55 changes: 55 additions & 0 deletions 08week/AddressBook/Addy.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

body {
font-family: sans-serif;
margin: 5% 10%;

}

button {
padding: 5px 10px;
background: #9ca9bf;
border-radius: 20px;
color: white;
font-size: 12px;
letter-spacing: 2px;
text-transform: uppercase;
margin: 10px 0px;
}



img {
height: 85px;
width: 85px;
border-radius: 50%;
margin-right: 20px;
}

ul {
list-style-type: none;
}

li {
flex-direction: row;
align-items: center;
justify-content: center;
}

.contact-image {
float: left;
}

.contact::after {
content: "";
clear: both;
display: table;
}

.contact {
margin: 40px 0px;
}

#contacts {
margin: 0px;
padding: 0px;
}
18 changes: 18 additions & 0 deletions 08week/AddressBook/Addy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="style.css" />
<title>Address Book</title>
</head>
<body>
<h1>Address Book</h1>
<ul id="contacts"></ul>

<script src="./addy.js"></script>
</body>

</html>
53 changes: 53 additions & 0 deletions 08week/AddressBook/addy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
let contactsArray;


const getContacts = () => {
fetch("https://randomuser.me/api/?results=10")
.then((res) => res.json())
.then((users) => {
contactsArray = users.results;
displayContacts();
});
}

const displayContacts = () => {

const contactsList = document.getElementById("contacts");
contactsArray.map((user) => {
console.log(contactsArray[0]);
const li = document.createElement("li");
li.className = "contact";
const contactImg = document.createElement("img");
contactImg.className = "contact-image";
contactImg.src = user.picture.medium;
const text = document.createTextNode(
`${user.name.last}, ${user.name.first}`
);
text.className = "contact-name";

linebreak = document.createElement("br");
contactsList.append(li);
li.appendChild(contactImg);
li.appendChild(text);
li.appendChild(linebreak);

const button = document.createElement("button");
button.innerHTML = "more info";
button.onclick = function () {
const contactDetails = document.createTextNode(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have been nice if you added a toggle, to hid and show the extra info, instead of always appending more info

` ${user.cell}, ${user.phone}, ${(user.location.street.number,
user.location.street.name)}, ${user.location.city}, ${
user.location.state
}, ${user.location.postcode}`
);
contactDetails.className = "contact-details";
li.appendChild(linebreak);
li.appendChild(contactDetails);
};
li.appendChild(button);
});
};

window.onload = () => {
getContacts();
};