Skip to content
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
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* {
text-align: center;
background-color: blue;
color: white;
}
26 changes: 26 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Auto Text</title>
<link rel="stylesheet" href="css/main.css">
<script src="https://kit.fontawesome.com/e391ce7786.js" crossorigin="anonymous"></script>
<script src="js/main.js" defer></script>
</head>

<body>
<div class="container">
<div class="joke">
<h2>Don't Laugh Challenge</h2>
<div class="txt">
<p></p>
</div>
</div>
<button id="btn">Get Random Joke</button>

</div>
</body>

</html>
16 changes: 16 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const joke = document.querySelector('.joke');
const btn = document.getElementById('btn');
const jokeParagraph = document.querySelector('.joke p');

// Getting data from the Api using Fetch with Async Await Syntax.
btn.addEventListener('click', getRandom);
getRandom();
async function getRandom() {
const jokeRes = await fetch('https://icanhazdadjoke.com/', {
headers: {
'Accept': 'application/json'
}
});
const resJson = await jokeRes.json();
jokeParagraph.innerHTML = resJson.joke;
}