From 6fd5e034826f02e0a578ec6b4aa962079e99aedd Mon Sep 17 00:00:00 2001 From: Juan Marco Date: Wed, 22 Jun 2022 10:18:44 +0200 Subject: [PATCH] Fix NaN input for Battle --- 09_Battle/javascript/battle.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/09_Battle/javascript/battle.js b/09_Battle/javascript/battle.js index 8ffb7fa0..46c2ccd0 100644 --- a/09_Battle/javascript/battle.js +++ b/09_Battle/javascript/battle.js @@ -258,6 +258,11 @@ async function main() print("START GAME\n"); while (1) { str = await input(); + // Check if user types anything other than a number + if (isNaN(str)) { + print("INVALID INPUT. TRY ENTERING A NUMBER INSTEAD.\n") + continue + } x = parseInt(str); y = parseInt(str.substr(str.indexOf(",") + 1)); if (x < 1 || x > 6 || y < 1 || y > 6) {