From bbdec7dd4b4eebf0fbae846f154ef6b9980a384c Mon Sep 17 00:00:00 2001 From: AbiAsalesh Date: Tue, 5 May 2026 21:43:24 +0530 Subject: [PATCH] Add defensive check to prevent errors when quotes list is empty --- 4-typing-game/solution/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/4-typing-game/solution/index.js b/4-typing-game/solution/index.js index 55a4f3922..b9902deae 100644 --- a/4-typing-game/solution/index.js +++ b/4-typing-game/solution/index.js @@ -30,7 +30,13 @@ const messages = { }; // Utility: pick random quote -const getRandomQuote = () => quotes[Math.floor(Math.random() * quotes.length)]; +const getRandomQuote = () => { + if (!Array.isArray(quotes) || quotes.length === 0) { + return ""; + } + const index= MAth.floor(Math.random() * quotes.length); + return quotes[index]; +}; // Utility: render quote as spans const renderQuote = (quote) => {