Skip to content
Open
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
33 changes: 15 additions & 18 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,28 @@
input.classList.add("score-edit");
input.type = "number";

var exit = function() {
scoreContainer.isOpen = false;
showPlay();
};

scoreContainer.isOpen = false;
scoreContainer.addEventListener("mouseup", function(evt) {
scoreContainer.isOpen = !scoreContainer.isOpen;

if(scoreContainer.isOpen) {
scoreContainer.appendChild(input);
input.value = con.score;
input.focus();
input.select();
} else {
scoreContainer.removeChild(input);
}
});

var exit = function() {
scoreContainer.isOpen = false;
scoreContainer.removeChild(input);
var userInput = prompt("Enter the number of points to add:");
var pointsToAdd = parseInt(userInput, 10);

var score = !!input.value ? parseFloat(input.value) : 0;
// Check if the input is a valid number
if (!isNaN(pointsToAdd)) {
// Add the points to the contestant's score
con.score += pointsToAdd;

if (con.score != score) {
con.score = score;
showPlay();
exit();
} else {
alert("Please enter a valid number.");
}
};
});

input.addEventListener("focusout", exit);
input.addEventListener("onkeydown", function(evt) {
Expand Down