Hey there, I could really use some assistance. Currently, I am learning Javascript as a part of a project I am working on and I seem to have run into a bit of an issue with updating the display status of a button on my webpage.
I am trying to set up a condition where a button appears or disappears based on whether a certain condition is met.
I have two buttons that should each be clicked a specific number of times (let's say 12 and 13). I have managed to create a condition where if button1 == 12 && button2 == 13, then change the button status to block instead of hidden. However, once this condition is met, if I click either button again, the button that should appear after the condition stays visible even though the condition is no longer true.
//var clickNeeded = 12;
var clicks = 0;
var clicks1 = 0;
function countDown() {
clicks += 1;
document.getElementById("test").innerHTML = clicks;
if (clicks == 12 && clicks1 == 13){
document.getElementById("step1").style.display = 'block';
}
};
function countDown1() {
clicks1 += 1;
document.getElementById("test1").innerHTML = clicks1;
if (clicks == 12 && clicks1 == 13){
document.getElementById("step1").style.display = 'block';
}
};
if (clicks != 12 && clicks1 != 13){
document.getElementById("step1").style.display = 'hidden';
}
function messageAfficher() {
document.getElementById("enigme").style.display = 'block';
}
body{
background-color: black;
}
@font-face{
font-family: 'hacked';
src: url(font/Hacked-KerX.ttf);
font-style: normal;
}
.header{
text-align: center;
margin: 50px 100px;
font-family: hacked;
}
.header h1{
color: purple;
font-size: 80px;
margin: 50px
}
.header p{
color: purple;
font-size: 20px;
text-align: justify;
padding-right: 100px;
padding-left: 100px;
}
.enigme {
color: aliceblue;
text-align: center;
font-family: hacked;
}
.step {
display: flex;
justify-content: center;
align-items: center;
height: 50px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="fonction.js"></script>
<title>Escape Game</title>
<link rel="stylesheet" href="main.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<!--===========================================================================================================================-->
<body>
<div class="header">
<h1>Welcome to this adventure!</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt...
</p>
</div>
<div class="step">
<button id="test" onclick="countDown()">0</button>
</div>
<div class="step">
<button id="test1" onclick="countDown1()">0</button>
</div>
<div class="step">
<button id="step1" onclick="messageAfficher()" style="display:none">Where am I?</button>
</div>
<div class="enigme">
<p id="enigme" style="display:none">Coordinates</p>
</div>
</body>
<!--===========================================================================================================================-->
</html>
I've tried adding an If condition after my function, but it doesn't seem to work, which makes sense, given that it's not quite logical. So, I'm a bit stuck here ^^'
Thanks in advance! :D