File tree 5 files changed +115
-0
lines changed
5 files changed +115
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Initialize EasyHTTP object
2
+ const http = new EasyHTTP ;
3
+ const ui = new UI ( ) ;
4
+
5
+
6
+ document . getElementById ( "next" ) . addEventListener ( "click" , ( ) => {
7
+
8
+ // Get randow users
9
+ http . get ( 'https://randomuser.me/api/' )
10
+ . then ( data => {
11
+ console . log ( data ) ;
12
+ ui . pictureProfile ( data ) ;
13
+ } )
14
+ . catch ( err => console . log ( err ) ) ;
15
+ } )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * EasyHTTP2 Library
3
+ * Cool library for making HTTP requests
4
+ *
5
+ * @version 3.0.0
6
+ * @author Kate Lo
7
+ * @license MIT
8
+ *
9
+ **/
10
+
11
+ class EasyHTTP {
12
+
13
+ // Make an HTTP GET Request
14
+ async get ( url ) {
15
+ const response = await fetch ( url ) ;
16
+ const resData = await response . json ( ) ;
17
+ return resData ;
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < title > Profile Scroller</ title >
6
+ <!-- Required meta tags -->
7
+ < meta charset ="utf-8 ">
8
+ < meta name ="viewport " content ="width=device-width, initial-scale=1, shrink-to-fit=no ">
9
+
10
+ <!-- Bootstrap CSS -->
11
+ < link rel ="stylesheet " href ="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css " integrity ="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb "
12
+ crossorigin ="anonymous ">
13
+ < link rel ="stylesheet " href ="styles.css ">
14
+ </ head >
15
+
16
+ < body >
17
+ < div class ="container ">
18
+ < div class ="row ">
19
+ < div class ="col-md-6 mx-auto text-center ">
20
+ < h1 class ="mb-3 "> Profile Scroller</ h1 >
21
+ < div id ="profile ">
22
+ </ div >
23
+ < button id ="next " class ="btn btn-dark btn-block "> Next</ button >
24
+ </ div >
25
+ </ div >
26
+ </ div >
27
+
28
+ <!-- Optional JavaScript -->
29
+ <!-- jQuery first, then Popper.js, then Bootstrap JS -->
30
+ < script src ="https://code.jquery.com/jquery-3.2.1.slim.min.js " integrity ="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN "
31
+ crossorigin ="anonymous "> </ script >
32
+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js " integrity ="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh "
33
+ crossorigin ="anonymous "> </ script >
34
+ < script src ="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js " integrity ="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ "
35
+ crossorigin ="anonymous "> </ script >
36
+ < script src ="easyhttp3.js "> </ script >
37
+ < script src ="ui.js "> </ script >
38
+ < script src ="app.js "> </ script >
39
+ </ body >
40
+
41
+ </ html >
Original file line number Diff line number Diff line change
1
+ # location ,
2
+ # lastname ,
3
+ # firstname {
4
+ text-transform : capitalize;
5
+ }
Original file line number Diff line number Diff line change
1
+ class UI {
2
+ constructor ( ) {
3
+ this . profile = document . getElementById ( "profile" ) ;
4
+ }
5
+
6
+ pictureProfile ( data ) {
7
+
8
+ console . log ( data . results [ 0 ] ) ;
9
+
10
+ this . profile . innerHTML = `
11
+ <div id="imageDisplay">
12
+ <img src="${ data . results [ 0 ] . picture . large } ">
13
+ </div>
14
+ <span>Gender:</span>
15
+ <span id="gender">${ data . results [ 0 ] . gender } </span>
16
+ <br>
17
+ <span>Age:</span>
18
+ <span id="age">${ data . results [ 0 ] . dob . age } </span>
19
+ <br>
20
+ <span>Name:</span>
21
+ <span id="firstname">${ data . results [ 0 ] . name . first } </span>
22
+ <span id="lastname">${ data . results [ 0 ] . name . last } </span>
23
+ <br>
24
+ <br>
25
+ <div id="profileDisplay">
26
+ <span>Ceil phone:</span>
27
+ <span id="cell">${ data . results [ 0 ] . cell } </span>
28
+ <br>
29
+
30
+ <span>Location:</span>
31
+ <span id="location">${ data . results [ 0 ] . location . city } </span>
32
+ </div>
33
+ <br>` ;
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments