Instead of rewriting the same code, we can use functions to group related code and perform the task in one place.

<html>
<head>
<style>
body { text-align: center; height: 275px; font-size: 16px; margin: 0 auto; background-color: #F0F8FF; } button { background-color: darkBlue; border: none; border-radius: 8px; color: white; text-align: center; text-decoration: none; display: inline-block; font-size: 14px; padding: 6px 12px; margin: 0 12px 0 0; } h2 { text-align: center; } #playerList { text-align: left; }
</style>
</head>
<body>
<img height=180 src="https://mimo.app/i/volume-icon.png"><br>
<button onclick="decrease()">Decrease volume</button>
<p id="container">
</div>
<script>
var volume = 0;
function decrease() {
document.getElementById("container").innerHTML = "Volume decreased!";
var s = document.getElementById('container').style;
s.display="block";
s.opacity = 1;
(function fade() {
    if ((s.opacity-=.1) < 0)
        s.display="none";
    else
        setTimeout(fade,150);
})();
}
</script>
</body>
</html>]]>