-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomu.js
149 lines (114 loc) · 5.04 KB
/
randomu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
async function randomUsersAPI() {
let firstName = document.getElementById("first-Name").value;
firstName= firstName.toLowerCase();
const femaleGender = document.getElementById("femalegen").value;
const maleGender = document.getElementById("malegen").value;
const age = document.getElementById("user-age").value;
let gender= document.getElementById("genders").value;
const listUsers = [];
// console.log(`My selected gender is ${gender}`);
//i need a way for my code to figure out what all the genders are without me hardcoding them in. So I need a loop to go through the results and find the distinct gender object keys.
console.log(firstName);
//But first need to connect to the API.
const endpoint = new URL(`https://randomuser.me/api/?gender=${ gender }&name=${ firstName }&age=${ age }&results=5000`)
//realized i had to make results last
// console.log(endpoint);
// console.log(gender);
// console.log(typeof firstName);
// console.log(`I am this years many old ${age}`);
// all the search fields that are defined
let searchCritera;
const response = await fetch(endpoint);
// console.log(response);
let data = await response.json();
// console.log (data);
let user= data.results;
// console.log(`what is user ${user}`);
// console.log(`what is maxage ${age}`);
// console.log(`These are our users ${user}`);
let div = document.getElementById("results-api");
// let div2 = document.getElementById("results-api2");
// document.getElementById('reesults-api').innerHTML = output;
// console.log(`You're supposed to be the age? ${user.dob.age}`);
// if (user.dob.age <= maxage){
// console.log(`I am less than ${maxage}`);
// }
// else {
// console.log(`You are not working.`);
// }
// user.forEach(function (lists) {
// div.innerHTML= `
// <div class="container">
// <div class="card mt-4 bg-light">
// <ul class="list-group">
// <li class="list-group-item"><h2>Name: ${lists.name.first}</h2></li>
// <li class="list-group-item"><img src="${lists.picture.large}"></li>
// <li class="list-group-item">Phone Number: ${lists.cell}</li>
// <li class="list-group-item">DOB: ${lists.dob.date}</li>
// <li class="list-group-item">Age: ${lists.dob.age}</li>
// <li class="list-group-item">Email ID: ${lists.email}</li>
// <li class="list-group-item">Gender: ${lists.gender}</li>
// <li class="list-group-item">City: ${lists.location.city}</li>
// <li class="list-group-item">Country: ${lists.location.country}</li>
// <li class="list-group-item">PostCode: ${lists.location.postcode}</li>
// </ul>
// </div>
// </div> `
// });
let resultsDiv= document.getElementById("results-api");
// function clearResults() {
// resultsDiv.style.display= "none";
// return;
// }
if (!firstName){
alert("Please enter a first name");
}
user.forEach(function (lists) {
// console.log(firstName);
let usersName= lists.name.first.toLowerCase()
// console.log(usersName);
// console.log(lists.name.first);
if (usersName == firstName && lists.dob.age <= age) {
div.innerHTML= `
<div class="container">
<div class="card mb-4">
<div class ="card-header">
<h4>Results</h4>
</div>
<ul class="list-group">
<li class="list-group-item"><h2>Name: ${lists.name.first}</h2></li>
<li class="list-group-item"><img src="${lists.picture.large}"></li>
<li class="list-group-item">Phone Number: ${lists.cell}</li>
<li class="list-group-item">DOB: ${lists.dob.date}</li>
<li class="list-group-item">Age: ${lists.dob.age}</li>
<li class="list-group-item">Email ID: ${lists.email}</li>
<li class="list-group-item">Gender: ${lists.gender}</li>
<li class="list-group-item">City: ${lists.location.city}</li>
<li class="list-group-item">Country: ${lists.location.country}</li>
<li class="list-group-item">PostCode: ${lists.location.postcode}</li>
</ul>
<button id="resetBtn" class = "btn btn-primary btn-block" onclick="clearResults()">Reset</button>
</div>
</div> `
}
// else{
// div.innerHTML = `
// <div class="container">
// <div class="card mt-4 bg-light">
// <h4>No Results</h4>
// </div>
// </div>`
// }
});
// console.log("this is the name?" + data.results.name);
// data.JSON.stringify(data);
// console.log(typeof data.results[0].name)
// let name = data.results[0].name;
// name = JSON.stringify(name)
// console.log(`this should be a string ${typeof name}`)
// console.log(name);
// name= name.split(":");
// console.log(name);
// console.log(data.results[0].name);
// console.log(`what the fuck is ${JSON.stringify(user)}`);
}