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.
18 changes: 18 additions & 0 deletions Public/tell-me-a-joke.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Joke Teller</title>
<link rel="stylesheet" href="../assets/css/tell-me-a-joke.css">
<!-- <script rel="script" href="../assets/Js/tell-me-a-joke.js"></script> -->
</head>

<body>
<h1>Need a Laugh?</h1>
<button onclick="getJoke()">Tell me a joke</button>
<div id="joke"></div>
<script src="../assets/Js/tell-me-a-joke.js"></script>
</body>

</html>
36 changes: 36 additions & 0 deletions assets/Js/tell-me-a-joke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

async function getJoke() {
const res = await fetch('https://official-joke-api.appspot.com/random_joke');
const data = await res.json();

const setup = data.setup;
const punchline = data.punchline;

document.getElementById('joke').innerHTML = `${setup}<br><strong>${punchline}</strong>`;

speakWithPause(setup, punchline);
}

function speakWithPause(setup, punchline) {
// Cancel ongoing speech
window.speechSynthesis.cancel();

const first = new SpeechSynthesisUtterance(setup);
first.lang = 'en-US';
first.pitch = 0.95;
first.rate = 0.9;

const second = new SpeechSynthesisUtterance(punchline);
second.lang = 'en-US';
second.pitch = 0.95;
second.rate = 0.85;

first.onend = () => {
setTimeout(() => {
speechSynthesis.speak(second);
}, 600); // 600ms pause before punchline
};

speechSynthesis.speak(first);
}

53 changes: 53 additions & 0 deletions assets/css/tell-me-a-joke.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background: #f4f1ee;
font-family: 'Georgia', serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
padding: 20px;
}

h1 {
font-size: 36px;
color: #2c3e50;
margin-bottom: 40px;
}

button {
background: #2c3e50;
color: #fff;
border: none;
padding: 14px 28px;
font-size: 18px;
border-radius: 6px;
cursor: pointer;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
transition: background 0.3s ease, transform 0.2s ease;
}

button:hover {
background: #34495e;
transform: scale(1.03);
}

#joke {
margin-top: 40px;
font-size: 22px;
line-height: 1.6;
max-width: 600px;
text-align: center;
color: #333;
background: #fff;
padding: 25px 30px;
border-radius: 10px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}