From 498ab5502a43d6dddb1a07afe3a8f95355767d1a Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Tue, 6 Jul 2021 20:36:01 +0300 Subject: [PATCH] make several correct answer --- TODO.md | 6 ++---- app/gameData.json | 4 ++-- js/game.js | 22 ++++++++++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 1896257..b03c8d0 100644 --- a/TODO.md +++ b/TODO.md @@ -1,11 +1,9 @@ -- loading all quest images with loading -- splash (loading) screen - several correct answer - change quest animation - button hover animation - make docs/ -- google: if webpack mode production remove DEBUG code - ## done +- loading all quest images with loading [b8aa4b6] +- splash (loading) screen [b8aa4b6] - add quest progress [aac38ec] diff --git a/app/gameData.json b/app/gameData.json index 20114be..631ef7c 100644 --- a/app/gameData.json +++ b/app/gameData.json @@ -1,10 +1,10 @@ { "questions": [ { - "question": "Выбери вариант МОСТ", + "question": "Выбери вариант МОСТ или РЕКА", "image": "image_land.jpg", "answer": [ "Мост", "Рудник", "Река", "Солнце" ], - "rightAnswer": "мост" + "rightAnswer": [ "мОст", "РЕКА" ] }, { "question": "Что горит?", diff --git a/js/game.js b/js/game.js index cbc4701..99c4925 100644 --- a/js/game.js +++ b/js/game.js @@ -19,11 +19,25 @@ export function imagePreloader(images, callback) { } export function checkAnswer(quest, answer) { - if (quest.rightAnswer.toLowerCase() == answer.toLowerCase()) { - quest.status = true; + if (Array.isArray(quest.rightAnswer)) { + let lowerCaseArray = []; + + quest.rightAnswer.forEach(item => lowerCaseArray.push(item.toLowerCase())) + + if (lowerCaseArray.includes(answer.toLowerCase())) { + quest.status = true; + } + else { + quest.status = false; + } + } + else { + if (quest.rightAnswer.toLowerCase() == answer.toLowerCase()) { + quest.status = true; + } + else + quest.status = false; } - else - quest.status = false; } export function shuffle(array) {