File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ let btn = document . querySelector ( "button" ) ;
2+ let p = document . querySelector ( "p" ) ;
3+
4+ btn . addEventListener ( "click" , async ( ) => {
5+ let fact = await getFacts ( ) ;
6+ p . innerText = fact ;
7+ } ) ;
8+
9+ let url = "https://catfact.ninja/fact" ;
10+ async function getFacts ( ) {
11+ try {
12+ let res = await axios . get ( url ) ;
13+ //console.log(res.data.fact)
14+ return res . data . fact ;
15+ } catch ( e ) {
16+ console . log ( "ERROR:-" , e ) ;
17+ return "No fact found" ;
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Cat Facts</ title >
7+ </ head >
8+ < body >
9+ < h1 > Get Cat Facts</ h1 >
10+ < button > click to get Facts</ button >
11+ < p id ="result "> </ p >
12+
13+ < script src ="https://cdn.jsdelivr.net/npm/axios@1.13.2/dist/axios.min.js "> </ script >
14+ < script src ="app.js "> </ script >
15+ </ body >
16+ </ html >
You can’t perform that action at this time.
0 commit comments