From 12dd6085b2d3794801d973a161214fb975ecc7b4 Mon Sep 17 00:00:00 2001 From: Tomer S Date: Tue, 27 Feb 2024 19:03:10 -0500 Subject: [PATCH] feat: Prompt for a score difference --- js/index.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/js/index.js b/js/index.js index 22ba908..9056a7a 100644 --- a/js/index.js +++ b/js/index.js @@ -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) {