Skip to content
Open
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
95 changes: 92 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,99 @@
<html lang="en">
<head>
<title>Exercise 3</title>
<style>
* {
box-sizing: border-box;
}

#myInput
{
background-image: url('/css/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}

#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}

#myTable th, #myTable td {
text-align: left;
padding: 12px;
}

#myTable tr {
border-bottom: 1px solid #ddd;
}

#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<center>
<h1>Daftar Planet</h1>
</center>
<center>
<h1>Daftar People</h1>
<h1>People List</h1>
</center>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for people names..">
<table id="myTable">
<thead>
<tr class="header">
<th style="width: 20%;">Name</th>
<th style="width: 20%;">Gender</th>
<th style="width: 20%;">Height</th>
<th style="width: 20%;">Skin Color</th>
<th style="width: 20%;">Hair Color</th>
</tr>
</thead>
<tbody id="datapeoples">
</tbody>
</table>

<script>
var display="";
for(var i=1;i<100;i++)
{
fetch("https://swapi.co/api/people/"+i)
.then(data => { return data.json() })
.then(res => { display += '<tr><td>'+res.name+'</td>'
display += '<td>'+ res.gender+'</td>'
display += '<td>'+ res.height+'</td>'
display += '<td>'+ res.skin_color+'</td>'
display += '<td>'+ res.hair_color+'</td></tr>'
console.log('peoples: ', res.name,i);
document.getElementById("datapeoples").innerHTML = display;
}).catch(err => console.error(err));
}
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td)
{
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1)
{
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</body>
</html>