Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prompt for a score difference #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
feat: Prompt for a score difference
tomershvueli committed Feb 28, 2024
commit 12dd6085b2d3794801d973a161214fb975ecc7b4
33 changes: 15 additions & 18 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -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) {