Skip to content

ZA | ITP-May-2025 | Revive Munashe Mapfumo | Module-Data-Groups | Quote generator app #604

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

Open
wants to merge 5 commits 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
7 changes: 5 additions & 2 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<title>Quote generator app</title>
<script defer src="quotes.js"></script>
<link rel ="stylesheet" href ="style.css"></link>
</head>
<body>
<h1>hello there</h1>
<h1 id = "welcome">Your Daily Motivation</h1>
<p id="quote"></p>
<p id="author"></p>
<div id ="quote-display"></div>
<button type="button" id="new-quote">New quote</button>
<button id="autoplay-toggle">Autoplay:OFF</button>
</body>
</html>
43 changes: 42 additions & 1 deletion Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,45 @@ const quotes = [
},
];

// call pickFromArray with the quotes array to check you get a random quote
// initial quote upon initial loading of the app
const initialQuote = pickFromArray(quotes);
document.getElementById("quote").textContent = `"${initialQuote.quote}"`;
document.getElementById("author").textContent = initialQuote.author;

const QuoteButton = document.getElementById("new-quote");
const displayQuote = document.getElementById("quote-display");

// call pickFromArray with the quotes array to get a random quote
//this method is for displaying new quotes and will be called every time we need a new quote
function displayNewQuote() {
const randomQuote = pickFromArray(quotes);
document.getElementById("quote").textContent = `"${randomQuote.quote}"`;
document.getElementById("author").textContent = randomQuote.author;
}
QuoteButton.addEventListener("click", displayNewQuote);

let autoplayInterval;
let isAutoplayOn = false;

const autoplayButton = document.getElementById("autoplay-toggle");
autoplayButton.classList.add("autoplay-off");

autoplayButton.addEventListener("click", function () {
if (isAutoplayOn) {
//off autoplay
clearInterval(autoplayInterval);
isAutoplayOn = false;
autoplayButton.textContent = "Autoplay:OFF";
autoplayButton.classList.remove("autoplay-on");
autoplayButton.classList.add("autoplay-off");
} else {
//on autoplay
autoplayInterval = setInterval(displayNewQuote, 5000);
isAutoplayOn = true;
autoplayButton.textContent = "Autoplay:ON";
autoplayButton.classList.remove("autoplay-off");
autoplayButton.classList.add("autoplay-on");
}
});

window.addEventListener("load", displayNewQuote);
83 changes: 83 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,84 @@
/** Write your CSS in here **/

/*active state when clicked*/
#new-quote:hover {
background-color: #0056b3;
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
smooth transitions #new-quote {
transition: all 0.3s ease;
}
/*modern gradient style */
#new-quote,
#autoplay-toggle {
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 15px 30px;
font-size: 16px;
font-weight: bold;
border-radius: 25px;
cursor: pointer;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
transition: all 0.3s ease;
}
/*quote stlying*/
#quote {
font-size: 24px;
font-style: italic;
color: #b34f77;
line-height: 1.6;
margin: 20px 0;
text-align: center;
font-weight: 300;
}
/*add quotation marks*/
#quote::before {
content: "";
font-size: 30px;
color: #c12d2d;
}

#quote::after {
content: "";
font-size: 30px;
color: #667eea;
}
#author {
font-size: 18px;
color: #8b3621;
text-align: center;
margin-top: 10px;
font-weight: 500;
font-weight: bold;
}
/*adding a dash before author name*/
#author::before {
content: "-";
}
body {
background: linear-gradient(to bottom, #f3f4fa 0%, #d1d9e6 100%);
}

h1 {
font-size: 42px;
background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-align: center;
font-weight: bold;
margin: 30px 0;
}

#autoplay-toggle:hover {
opacity: 0.8;
transform: translate(-1px);
}
.auto-play-off {
background-color: #6c757d;
}
.auto-play-on {
background-color: green;
}