File tree Expand file tree Collapse file tree 6 files changed +131
-0
lines changed Expand file tree Collapse file tree 6 files changed +131
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < meta charset ="UTF-8 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8
+ < title > API-javascript</ title >
9
+ </ head >
10
+
11
+ < body >
12
+ < h1 style ="text-align: center; "> Javascript API</ h1 >
13
+
14
+ < ul id ="users ">
15
+
16
+ </ ul >
17
+
18
+ < button onclick ="loadData() "> Load Data</ button >
19
+ < button onclick ="loadUsers() "> Load Users</ button >
20
+ < button onclick ="loadPosts() "> Load Posts</ button >
21
+
22
+
23
+ < script src ="js/app.js "> </ script >
24
+ </ body >
25
+
26
+ </ html >
Original file line number Diff line number Diff line change
1
+ function loadData ( ) {
2
+ fetch ( 'https://jsonplaceholder.typicode.com/todos/1' )
3
+ . then ( response => response . json ( ) )
4
+ . then ( json => console . log ( json ) )
5
+ }
6
+
7
+ function loadUsers ( ) {
8
+ fetch ( 'https://jsonplaceholder.typicode.com/users' )
9
+ . then ( response => response . json ( ) )
10
+ . then ( data => displayUser ( data ) ) ;
11
+ }
12
+
13
+ function loadPosts ( ) {
14
+ fetch ( 'https://jsonplaceholder.typicode.com/posts' )
15
+ . then ( response => response . json ( ) )
16
+ . then ( json => console . log ( json ) ) ;
17
+ }
18
+
19
+
20
+ function displayUser ( data ) {
21
+ const ul = document . getElementById ( 'users' ) ;
22
+ for ( const users of data ) {
23
+ console . log ( users . name ) ;
24
+ const li = document . createElement ( 'li' ) ;
25
+ li . innerText = `name: ${ users . name }
26
+ email: ${ users . email }
27
+
28
+ `
29
+ ul . appendChild ( li ) ;
30
+ }
31
+
32
+
33
+ }
Original file line number Diff line number Diff line change
1
+ function loadPosts ( ) {
2
+ fetch ( 'https://jsonplaceholder.typicode.com/posts' )
3
+ . then ( response => response . json ( ) )
4
+ . then ( data => displayPosts ( data ) ) ;
5
+ }
6
+
7
+ loadPosts ( ) ;
8
+
9
+ function displayPosts ( post ) {
10
+ console . log ( post ) ;
11
+ const section = document . getElementById ( 'section' ) ;
12
+ for ( const data of post ) {
13
+ const div = document . createElement ( 'div' ) ;
14
+ div . classList . add ( 'design' ) ;
15
+ div . innerHTML = `
16
+ <h3>${ data . title } </h3>
17
+ <p>${ data . body } </p>
18
+ `
19
+ section . appendChild ( div ) ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ const shop = {
2
+ name : "Peom Dutta" ,
3
+ address : "Chittagong" ,
4
+ profit : 15000 ,
5
+ owner : {
6
+ names : "HBD" ,
7
+ profession : "banker" ,
8
+ id : 10
9
+ } ,
10
+ isExpensive : true ,
11
+ } ;
12
+
13
+ console . log ( shop ) ;
14
+
15
+ const shopStringified = JSON . stringify ( shop ) ;
16
+ console . log ( shopStringified ) ;
17
+
18
+ const shopParsed = JSON . parse ( shopStringified ) ;
19
+ console . log ( shopParsed ) ;
20
+
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < meta charset ="UTF-8 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8
+ < title > post-javascript</ title >
9
+
10
+ < style >
11
+ .design {
12
+ background-color : bisque;
13
+ padding : 10px ;
14
+ margin : 10px ;
15
+ border : 1px solid rgb (204 , 33 , 33 );
16
+ border-radius : 10px ;
17
+ }
18
+ </ style >
19
+ </ head >
20
+
21
+ < body >
22
+ < h1 > Post Displaying</ h1 >
23
+
24
+ < section id ="section ">
25
+
26
+ </ section >
27
+
28
+ < script src ="js/post.js "> </ script >
29
+ </ body >
30
+
31
+ </ html >
You can’t perform that action at this time.
0 commit comments