From 0cdae05f6821e5d2a4182e63e3fd99b9860068f4 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Wed, 11 Jan 2023 18:30:54 +0100 Subject: [PATCH] Prevent index out of range --- Public/grid.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Public/grid.js b/Public/grid.js index bc4ceda..7a6c903 100644 --- a/Public/grid.js +++ b/Public/grid.js @@ -78,6 +78,10 @@ imageCanvas.addEventListener("click", function(event) { const currentPosition = row * numberOfColumns + column; + if (currentPosition >= numberOfCaps) { + return; + } + if (selectedPosition === null) { selectedPosition = currentPosition; const circlePositionX = rowIsEven ? column * capImageSize + halfCapImageSize : column * capImageSize;