mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 15:16:33 -08:00
Fix NaN input for Battle
This commit is contained in:
@@ -258,6 +258,11 @@ async function main()
|
|||||||
print("START GAME\n");
|
print("START GAME\n");
|
||||||
while (1) {
|
while (1) {
|
||||||
str = await input();
|
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);
|
x = parseInt(str);
|
||||||
y = parseInt(str.substr(str.indexOf(",") + 1));
|
y = parseInt(str.substr(str.indexOf(",") + 1));
|
||||||
if (x < 1 || x > 6 || y < 1 || y > 6) {
|
if (x < 1 || x > 6 || y < 1 || y > 6) {
|
||||||
|
|||||||
Reference in New Issue
Block a user