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

add new func #7

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
Binary file added Sad-Cat.jpg
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 images.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ <h1>Streetcat Rescue</h1>
<div id="cat-counter">Cat Clicks: 0</div>
<input class="happy" type="text" name="amount" id="amount" placeholder="Any amount helps!"/>
<button class="happy" id="btn">We appreciate your donation!</button>
if its to bright or to dark <button id="Switch">Click here</button>
</main>
<div><img src="Sad-Cat.jpg" alt="Sad-Cat" id="sad-cat-image"></div>
<script src="script.js"></script>
</body>
</html>
24 changes: 23 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const button = document.getElementById('btn');
const input = document.getElementById('amount');
const cat = document.getElementById('cat');
const sadCatImage = document.getElementById("sad-cat-image");

function handleDonation() {
const amount = input.value;

if (amount == 0) {
alert('Thanks for nothing, the cats are all sad :(');
document.body.style.background = 'red';
sadCatImage.src = "images.jpg";
sadCatImage.style.display = "block";
} else {
alert(`Thanks for the donation of $ ${amount}!`);
sadCatImage.style.display = "none";
}
}

Expand All @@ -31,9 +35,27 @@ function toggleCatClass() {
cat.classList.toggle("rotate");
}


button.addEventListener('click', handleDonation);
cat.addEventListener('click', catClick);
cat.addEventListener('click', moveCat);
cat.addEventListener('mouseover', toggleCatClass);
cat.addEventListener('mouseout', toggleCatClass);

document.addEventListener("DOMContentLoaded", function() {
const switchButton = document.getElementById("Switch");
const body = document.body;
let isLightBackground = true;

switchButton.addEventListener("click", function() {
if (isLightBackground) {
body.style.backgroundColor = "black";
body.style.color = "white";
} else {
body.style.backgroundColor = "lightblue";
body.style.color = "black";
}
isLightBackground = !isLightBackground;
});
});


2 changes: 1 addition & 1 deletion styles.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
body {
background: #28debd;
background: lightblue;
font-family: sans-serif;
color: #daae6d;
display: grid;
Expand Down