Currently, I am developing a web game where the website displays different emotions, including anger. I have successfully implemented the anger level internal coding and I am now focusing on adding a color-changing feature when the anger level reaches a specific value. My goal is to have the color shift slightly towards red when the anger level increases by 10. While I am not very experienced with CSS design, I usually incorporate existing designs that are available for use. Below, you can find the code that I am currently working with.
JavaScript Section
var anger = 0;
// Create a function that increments the anger level and updates the DOM
var incrementAndSet = function() {
anger = anger + 1;
document.getElementById("anger").innerHTML = "Anger level:" + anger;
console.log("Anger level:" + anger);
if (anger === 10) {
console.log("The site is very mad!!")
bgcolor: #ffb347;
}
if (anger === 20) {
console.log("The site is SUPER mad!!!")
bgcolor: #ff8243
}
if (anger === 0) {
bgcolor: #69F7BE;
}
}
// increment and set on click
document.getElementById('btn').onclick = incrementAndSet;
// initialize
incrementAndSet();
HTML Section
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="https://glitch.com/favicon.ico" />
<title>Hello world!</title>
<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="/style.css" />
<!-- import the webpage's javascript file -->
<script src="/script.js" defer></script>
</head>
<body>
<!-- this is the start of content -->
<h1>
Anger Minigame
</h1>
<p>
This site is a game, meant for you to press the below button,
making the site angrier and angrier.
<button id="btn">Click Me</button>
<div id='anger'>
</div>
</p>
</body>
</html>