I cant select the same number twice, I am trying to use select to input the number and use the function to add them together.
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" > </script>
<script>
const firstFunct = (() => {
let counter = 0;
return () => {
counter += +document.getElementById("mySelect").value;
document.getElementById("Group 1 score").innerHTML = counter;
if ((counter) >= 54) {
document.body.innerHTML = "<p class='Group'>Group 1 Win</p><p onClick='location.reload()' class='Again'>Again</p>";
}
};
})();
</script>
<form>
<select id="mySelect" onchange="firstFunct()">
<option value="" disabled selected style="display:none;">+</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>12</option>
<option>14</option>
<option>16</option>
<option value="1">1</option>
<option value="54">win</option>
</select>
</form>
<p id="Group 1 score" style="font-size: 75px;">0</p>
Change the firstFunct, as given below. The added line of code clears the last selected value after it has been added to the counter. That allows you to select the same value repetitively.
<script>
const firstFunct = (() => {
let counter = 0;
return () => {
counter += +document.getElementById("mySelect").value;
document.getElementById("mySelect").value = null; //**this would clear the last selected value
document.getElementById("Group 1 score").innerHTML = counter;
if ((counter) >= 54) {
document.body.innerHTML = "<p class='Group'>Group 1 Win</p><p onClick='location.reload()' class='Again'>Again</p>";
}
};
})();
</script>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments