import { useState, useEffect } from 'react'; // Fix the icon imports - use correct icon names from lucide-react import { HelpCircle, Trophy, Flame } from 'lucide-react'; export default function WhoSaidItQuiz() { // Quiz data - can be expanded or loaded from an external source const quizData = [ { quote: "I am a god.", correctAnswer: "Kanye", options: ["Kanye", "Napoleon"] }, { quote: "My greatest pain in life is that I will never be able to see myself perform live.", correctAnswer: "Kanye", options: ["Kanye", "Freddie Mercury"] }, { quote: "I'm the number one human being in music.", correctAnswer: "Kanye", options: ["Kanye", "Mozart"] }, { quote: "I am the voice of a generation.", correctAnswer: "Kanye", options: ["Kanye", "Bob Dylan"] }, { quote: "If you have the opportunity to play this game called life, you need to appreciate every moment.", correctAnswer: "Kanye", options: ["Kanye", "Confucius"] }, { quote: "I feel like I'm too busy writing history to read it.", correctAnswer: "Kanye", options: ["Kanye", "Winston Churchill"] }, { quote: "I am Warhol. I am the No. 1 most impactful artist of our generation.", correctAnswer: "Kanye", options: ["Kanye", "Banksy"] }, { quote: "I will go down as the voice of this generation.", correctAnswer: "Kanye", options: ["Kanye", "John Lennon"] }, { quote: "I'm a creative genius and there's no other way to word it.", correctAnswer: "Kanye", options: ["Kanye", "Leonardo da Vinci"] }, { quote: "My greatest award is what I'm about to do.", correctAnswer: "Kanye", options: ["Kanye", "Steve Jobs"] } ]; // State variables const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0); const [score, setScore] = useState(0); const [streak, setStreak] = useState(0); const [bestScore, setBestScore] = useState(0); const [selectedAnswer, setSelectedAnswer] = useState(null); const [showResult, setShowResult] = useState(false); const [gameOver, setGameOver] = useState(false); const [shuffledQuestions, setShuffledQuestions] = useState([]); // Load best score from local storage on component mount useEffect(() => { const savedBestScore = localStorage.getItem('whoSaidItBestScore'); if (savedBestScore) { setBestScore(parseInt(savedBestScore)); } // Shuffle questions const shuffled = [...quizData].sort(() => Math.random() - 0.5); setShuffledQuestions(shuffled); }, []); // Current question object const currentQuestion = shuffledQuestions[currentQuestionIndex] || quizData[0]; // Handle answer selection const handleAnswerSelect = (answer) => { if (selectedAnswer) return; // Prevent multiple selections setSelectedAnswer(answer); setShowResult(true); const isCorrect = answer === currentQuestion.correctAnswer; if (isCorrect) { setScore(score + 1); setStreak(streak + 1); } else { setStreak(0); } // Move to next question after a delay setTimeout(() => { setShowResult(false); setSelectedAnswer(null); if (currentQuestionIndex < shuffledQuestions.length - 1) { setCurrentQuestionIndex(currentQuestionIndex + 1); } else { setGameOver(true); // Update best score if needed const newScore = score + (isCorrect ? 1 : 0); if (newScore > bestScore) { setBestScore(newScore); localStorage.setItem('whoSaidItBestScore', newScore.toString()); } } }, 1500); }; // Restart the game const restartGame = () => { setCurrentQuestionIndex(0); setScore(0); setStreak(0); setSelectedAnswer(null); setShowResult(false); setGameOver(false); // Reshuffle questions const shuffled = [...quizData].sort(() => Math.random() - 0.5); setShuffledQuestions(shuffled); }; return (
"{currentQuestion.quote}"
Your final score: {score}/{shuffledQuestions.length}
{score > bestScore / 2 ? (Great job! You know your quotes well!
) : (Better luck next time!
)}This game is meant to highlight similarities between different forms of rhetoric.
It's intended to educate and create awareness, not to promote hate speech.