Skip to content

Commit

Permalink
Merge pull request #263 from songifi/frontend
Browse files Browse the repository at this point in the history
Frontend
  • Loading branch information
PeterOche authored Feb 23, 2025
2 parents b870427 + d2ec204 commit 09ef50a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion frontend/components/game/AnswerInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,20 @@ const AnswerInput = ({ onAnswer }) => {
setIsAnswerCorrect(false);
}, [currentQuestion]);

const validateAnswer = (answer) => {
if (selectedDifficulty === "Beginner") {
// For MCQ, compare the full string (song title - artist)
return answer === currentQuestion.correctAnswer;
} else {
// For text input, only compare the song title
const correctSongTitle = currentQuestion.correctAnswer.split(" - ")[0].toLowerCase().trim();
const userSongTitle = answer.toLowerCase().trim();
return correctSongTitle === userSongTitle;
}
};

const handleSubmitAnswer = (answer) => {
const isCorrect = answer === currentQuestion.correctAnswer;
const isCorrect = validateAnswer(answer);
setIsAnswerSubmitted(true);
setIsAnswerCorrect(isCorrect);
handleAnswer(isCorrect);
Expand Down
2 changes: 2 additions & 0 deletions frontend/store/gameStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export const useGameStore = create((set, get) => ({
return {
lyricsSnippet: snippet.lyricsSnippet,
correctAnswer: correctOption,
songTitle: snippet.songTitle,
artist: snippet.artist,
difficulty: snippet.difficulty,
options: selectedDifficulty === "Beginner" ? shuffledOptions : [],
};
Expand Down

0 comments on commit 09ef50a

Please sign in to comment.