Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vanilla javascript api fetching #465

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions dad-jokes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dad jokes
fetches random dad joke from icanhazdadjoke api
Binary file added dad-jokes/imgs/left-removebg-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dad-jokes/imgs/right-removebg-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions dad-jokes/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>dad hehe</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">

<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>

</head>
<body>
<div style="text-align:center">
<img src="imgs/right-removebg-preview.png" alt="">
</div>

<div class="row d-flex align-items-center" style="margin-top:-20vh;">
<div class="row d-flex justify-content-center">
<!--Grid column-->
<div class="col-lg-6 col-md-6 col-sm-6 text-center" id="box">
Here you shall see magik
</div>
<!--Grid column-->
</div>
<br>
<br>
<br>
<div class=" text-center d-flex align-items-center justify-content-center" style="height: 5rem;">
<button type="button" class="btn btn-primary">Random Dad Joke</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="script.js"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions dad-jokes/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


const dadjoke = async () =>{
try{
const head = {headers:{Accept:'application/json'}};
const response = await axios.get('https://icanhazdadjoke.com/',head);
return response.data.joke;
} catch(e){
alert("ERROR, no joke/or wrong api/ "+e);
return ('NO jokes available..')
}
}

const displayBox = document.querySelector('#box');
const btn = document.querySelector('button');

btn.addEventListener('click',async ()=>{
const joke = await dadjoke();
displayBox.innerHTML = `<h3> ${joke} </h3>`;
})
15 changes: 15 additions & 0 deletions dad-jokes/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
body{
background-color: rgb(196, 183, 183) !important;
}
img {
width: 100%;
height: auto;
max-width: 1000px;
}
#box{
background-color: whitesmoke !important;
border: 2px solid black;
border-radius: 20px;
padding-top: 1vh;
padding-bottom: 1vh;
}