/*========================================================== AI Detective Game Day 25 - 30 Days 30 AI Websites Challenge script.js ==========================================================*/ const generateBtn = document.getElementById("generateBtn"); const solveBtn = document.getElementById("solveBtn"); const restartBtn = document.getElementById("restartBtn"); const caseTitle = document.getElementById("caseTitle"); const caseStory = document.getElementById("caseStory"); const evidenceContainer = document.getElementById("evidenceContainer"); const suspectContainer = document.getElementById("suspectContainer"); const suspectSelect = document.getElementById("suspectSelect"); const resultBox = document.getElementById("resultBox"); const resultContent = document.getElementById("resultContent"); let currentCase = null; /*========================================================== DATABASE ==========================================================*/ const cases = [ { title:"The Museum Diamond Heist", story:"The priceless Aurora Diamond disappeared during a private exhibition. Security systems never detected an intruder, yet the display case was empty the next morning.", victim:"Museum Trust", suspects:[ { name:"Emma Carter", role:"Security Guard", motive:"Large gambling debt.", statement:"I never left my security station." }, { name:"Lucas Reed", role:"Curator", motive:"Wanted insurance money.", statement:"Everything was normal during closing." }, { name:"Sophia Blake", role:"Journalist", motive:"Looking for a career-changing story.", statement:"I left before the museum closed." }, { name:"Oliver Grant", role:"Electrician", motive:"Needed money urgently.", statement:"I only repaired the lighting." } ], evidence:[ "Hidden fingerprint on display glass", "Security camera disabled for exactly 4 minutes", "Fresh muddy footprints", "Broken display lock", "Anonymous threatening letter" ], criminal:1, reason:"Lucas Reed secretly disabled the security system, staged the theft for insurance money, and possessed detailed knowledge of the display lock." }, { title:"Luxury Hotel Murder", story:"A famous businessman was found dead inside a luxury hotel suite. Every suspect claims they were somewhere else when the incident happened.", victim:"Daniel Brooks", suspects:[ { name:"Grace Wilson", role:"Business Partner", motive:"Wanted company ownership.", statement:"I was attending dinner." }, { name:"Noah Turner", role:"Hotel Manager", motive:"Hidden financial fraud.", statement:"I was helping guests." }, { name:"Ethan Clark", role:"Chef", motive:"Personal revenge.", statement:"I never entered the suite." }, { name:"Ava Scott", role:"Assistant", motive:"Blackmailed by victim.", statement:"I stayed in my office." } ], evidence:[ "Poisoned wine glass", "Deleted phone messages", "Hotel master key used", "Financial documents", "Broken wristwatch" ], criminal:3, reason:"Ava Scott secretly entered using the master key and poisoned the victim after months of blackmail." }, { title:"University Exam Leak", story:"The final examination paper was leaked online hours before the exam. The administration needs the culprit identified immediately.", victim:"University Examination Board", suspects:[ { name:"Professor Ryan", role:"Course Coordinator", motive:"Protect department ranking.", statement:"The papers were locked safely." }, { name:"Mia Patel", role:"Teaching Assistant", motive:"Needed extra income.", statement:"I only printed attendance sheets." }, { name:"David Lee", role:"IT Administrator", motive:"Wanted revenge after suspension.", statement:"I fixed network issues." }, { name:"Sarah Kim", role:"Student Representative", motive:"Help classmates.", statement:"I had no access." } ], evidence:[ "USB drive found", "Printer activity at midnight", "Server login history", "Anonymous email", "Security door logs" ], criminal:2, reason:"David Lee used administrator access to copy the examination files and anonymously upload them." } ]; /*========================================================== GENERATE CASE ==========================================================*/ generateBtn.addEventListener("click",generateCase); restartBtn.addEventListener("click",generateCase); function generateCase(){ resultBox.classList.add("hidden"); const random=Math.floor(Math.random()*cases.length); currentCase=cases[random]; caseTitle.textContent=currentCase.title; caseStory.innerHTML= ` Incident:

${currentCase.story} `; renderEvidence(); renderSuspects(); fillSelect(); window.scrollTo({ top:0, behavior:"smooth" }); } /*========================================================== EVIDENCE ==========================================================*/ function renderEvidence(){ evidenceContainer.innerHTML=""; currentCase.evidence.forEach(item=>{ const card=document.createElement("div"); card.className="card"; card.innerHTML=`

Evidence

${item}

`; evidenceContainer.appendChild(card); }); } /*========================================================== SUSPECTS ==========================================================*/ function renderSuspects(){ suspectContainer.innerHTML=""; currentCase.suspects.forEach(person=>{ const card=document.createElement("div"); card.className="card"; card.innerHTML=`

${person.name}

Role: ${person.role}


Motive: ${person.motive}


Statement:
${person.statement}

`; suspectContainer.appendChild(card); }); } /*========================================================== SELECT ==========================================================*/ function fillSelect(){ suspectSelect.innerHTML=""; const defaultOption=document.createElement("option"); defaultOption.textContent="Select Suspect"; defaultOption.value=""; suspectSelect.appendChild(defaultOption); currentCase.suspects.forEach((person,index)=>{ const option=document.createElement("option"); option.value=index; option.textContent=person.name; suspectSelect.appendChild(option); }); } /*========================================================== SOLVE ==========================================================*/ solveBtn.addEventListener("click",()=>{ if(currentCase===null){ alert("Generate a case first!"); return; } if(suspectSelect.value===""){ alert("Choose a suspect."); return; } const choice=parseInt(suspectSelect.value); const criminal=currentCase.criminal; const guilty=currentCase.suspects[criminal]; resultBox.classList.remove("hidden"); if(choice===criminal){ resultContent.innerHTML=`

✅ Case Solved!


Excellent detective work.


Criminal: ${guilty.name}


Reason: ${currentCase.reason}

`; } else{ resultContent.innerHTML=`

❌ Wrong Accusation


You accused ${currentCase.suspects[choice].name}


The actual criminal was ${guilty.name}


AI Investigation: ${currentCase.reason}

`; } resultBox.scrollIntoView({ behavior:"smooth" }); }); /*========================================================== LOAD FIRST CASE ==========================================================*/ generateCase();