ÿþ<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>NEET Physics Assignment Generator</title> <link href="img/logo1.jpg" rel="icon"> <!-- Add jsPDF library --> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <style> /* All CSS styles remain the same as before */ :root { --primary: #4361ee; --primary-dark: #3f37c9; --secondary: #4895ef; --danger: #f72585; --success: #4cc9f0; --light: #f8f9fa; --dark: #212529; --gray: #6c757d; --border-radius: 12px; --box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); --transition: all 0.3s ease; } * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } body { background: linear-gradient(135deg, #f5f7fa 0%, #e2e8f0 100%); min-height: 100vh; display: flex; justify-content: center; align-items: center; padding: 20px; color: var(--dark); line-height: 1.6; } .container { width: 100%; max-width: 900px; background: white; border-radius: var(--border-radius); box-shadow: var(--box-shadow); overflow: hidden; transition: var(--transition); animation: fadeIn 0.5s ease-out; } @keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } } .header { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; padding: 30px 20px; text-align: center; position: relative; overflow: hidden; } .header::before { content: ''; position: absolute; top: -50px; right: -50px; width: 150px; height: 150px; background: rgba(255, 255, 255, 0.1); border-radius: 50%; } .header h1 { font-size: 2rem; margin-bottom: 10px; font-weight: 700; position: relative; z-index: 1; } .header p { font-size: 1rem; opacity: 0.9; position: relative; z-index: 1; } .content-area { padding: 30px; } .hidden { display: none !important; } .btn { display: inline-block; padding: 12px 28px; border-radius: 50px; font-weight: 600; cursor: pointer; transition: var(--transition); border: none; text-align: center; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); margin: 10px 5px; } .btn-primary { background: var(--primary); color: white; } .btn-primary:hover { background: var(--primary-dark); transform: translateY(-2px); box-shadow: 0 8px 15px rgba(67, 97, 238, 0.3); } .btn-success { background: var(--success); color: white; } .btn-success:hover { background: #3ab0d6; transform: translateY(-2px); box-shadow: 0 8px 15px rgba(76, 201, 240, 0.3); } .btn-danger { background: var(--danger); color: white; } .btn-danger:hover { background: #d3166b; transform: translateY(-2px); box-shadow: 0 8px 15px rgba(247, 37, 133, 0.3); } .btn-level { background: var(--light); color: var(--dark); border: 2px solid var(--gray); font-size: 1.2rem; padding: 15px 30px; width: 200px; } .btn-level:hover { transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); } .btn-level.selected { background: var(--primary); color: white; border-color: var(--primary); } .btn-group { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 20px 0; } .level-buttons { display: flex; justify-content: center; gap: 20px; margin: 30px 0; } .section-title { text-align: center; margin-bottom: 25px; color: var(--primary-dark); font-size: 1.5rem; position: relative; padding-bottom: 10px; } .section-title::after { content: ''; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 80px; height: 3px; background: var(--secondary); border-radius: 3px; } .checkbox-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; margin: 25px 0; } .checkbox-item { display: flex; align-items: center; } .checkbox-item input { margin-right: 10px; width: 18px; height: 18px; cursor: pointer; } .checkbox-item label { cursor: pointer; font-size: 0.95rem; } .generated-paper { padding: 30px; } .paper-header { text-align: center; margin-bottom: 30px; border-bottom: 2px solid var(--primary); padding-bottom: 20px; } .paper-header h2 { color: var(--primary-dark); margin-bottom: 5px; font-size: 1.8rem; } .paper-header h3 { color: var(--gray); margin-bottom: 5px; font-size: 1.2rem; font-weight: 500; } .paper-meta { display: flex; justify-content: space-between; margin-bottom: 25px; padding-bottom: 15px; border-bottom: 1px solid #eee; font-weight: 500; } .instructions { margin-bottom: 30px; padding: 20px; background: #f8f9fa; border-radius: var(--border-radius); } .instructions ol { padding-left: 20px; margin-top: 10px; } .instructions li { margin-bottom: 8px; } .question-section { margin-bottom: 30px; } .section-heading { font-weight: 600; color: var(--primary-dark); margin-bottom: 15px; padding-bottom: 5px; border-bottom: 1px solid #eee; } .question { margin-bottom: 20px; page-break-inside: avoid; } .question-text { font-weight: 500; margin-bottom: 8px; } .option { margin-left: 20px; margin-bottom: 5px; } .action-buttons { display: flex; justify-content: center; flex-wrap: wrap; gap: 15px; margin-top: 40px; } .answer-sheet { margin-top: 40px; padding: 20px; background: #f8f9fa; border-radius: var(--border-radius); } .answer-table { width: 100%; border-collapse: collapse; margin-top: 15px; } .answer-table th, .answer-table td { border: 1px solid #ddd; padding: 8px; text-align: center; } .answer-table th { background-color: var(--primary); color: white; } .answer-table tr:nth-child(even) { background-color: #f2f2f2; } @media (max-width: 768px) { .header h1 { font-size: 1.6rem; } .content-area { padding: 20px; } .checkbox-container { grid-template-columns: 1fr; } .btn { padding: 10px 20px; font-size: 0.9rem; } .btn-level { width: 150px; font-size: 1rem; padding: 12px 20px; } .level-buttons { flex-direction: column; align-items: center; } .paper-header h2 { font-size: 1.4rem; } .paper-header h3 { font-size: 1rem; } } @media (max-width: 480px) { .header { padding: 20px 15px; } .section-title { font-size: 1.3rem; } .paper-meta { flex-direction: column; gap: 10px; } .action-buttons { flex-direction: column; align-items: center; } .btn { width: 100%; max-width: 250px; } .btn-level { width: 100%; max-width: 200px; } } @media print { body { background: none; padding: 0; } .container { box-shadow: none; max-width: 100%; } .action-buttons { display: none; } .question { page-break-inside: avoid; } } </style> <style> /* Ensure header styling is preserved */ .header { background: linear-gradient(135deg, #4361ee, #3f37c9) !important; color: white !important; padding: 30px 20px !important; text-align: center !important; position: relative !important; overflow: hidden !important; width: 100% !important; } .header h1, .header h2, .header h3 { color: white !important; font-weight: bold !important; } .temp-pdf-container { font-family: Arial, sans-serif; line-height: 1.5; width: 794px; /* A4 width in pixels (210mm) */ background-color: white; color: black; } /* Page break control */ .question { page-break-inside: avoid; break-inside: avoid; } .question-section { page-break-after: auto; } @media print { body { margin: 0 !important; padding: 0 !important; background: white !important; } .container { width: 100% !important; margin: 0 !important; padding: 0 !important; box-shadow: none !important; } .header { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; } } /* Home icon styles */ .home-icon { position: absolute; top: 20px; left: 20px; color: white; font-size: 24px; cursor: pointer; transition: var(--transition); z-index: 2; } .home-icon:hover { transform: scale(1.1); color: rgba(255, 255, 255, 0.8); } @media (max-width: 480px) { .home-icon { font-size: 20px; top: 15px; left: 15px; } } @media print { .home-icon { display: none; } } </style> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4930137336556867" crossorigin="anonymous"></script> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-KMZ9RJ62EY"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KMZ9RJ62EY'); </script> </head> <body> <div class="container" id="startContainer"> <div class="header"> <!-- Home icon added here --> <a href="Neet-exam-assignment-generator.html" class="home-icon"> <i class="fas fa-home"></i> </a> <h1>NEET Physics</h1> <p>Generate Customized Assignments</p> </div> <div class="content-area"> <div id="startScreen"> <h2 class="section-title">NEET Physics Assignment Generator</h2> <div class="btn-group"> <button class="btn btn-primary" id="startGeneratingBtn">Start Generating</button> </div> </div> <div id="physicsOptions" class="hidden"> <h2 class="section-title">Select Physics Course</h2> <div class="btn-group"> <button class="btn btn-primary" id="selectPhysicsBtn">Physics</button> </div> </div> <div id="chapterSelection" class="hidden"> <h2 class="section-title">Select Chapters</h2> <form id="chapterForm"> <div class="checkbox-container"> <div class="checkbox-item"> <input type="checkbox" id="fullPaper" name="chapter" value="Full Paper"> <label for="fullPaper">Full Syllabus (All Chapters)</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter1" name="chapter" value="Chapter 1"> <label for="chapter1">1. Units and Measurement</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter2" name="chapter" value="Chapter 2"> <label for="chapter2">2. Motion in a Straight Line</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter3" name="chapter" value="Chapter 3"> <label for="chapter3">3. Motion in a Plane</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter4" name="chapter" value="Chapter 4"> <label for="chapter4">4. Laws of Motion</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter5" name="chapter" value="Chapter 5"> <label for="chapter5">5. Work, Energy and Power</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter6" name="chapter" value="Chapter 6"> <label for="chapter6">6. System of Particles and Rotational Motion</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter7" name="chapter" value="Chapter 7"> <label for="chapter7">7. Gravitation</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter8" name="chapter" value="Chapter 8"> <label for="chapter8">8. Mechanical Properties of Solids</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter9" name="chapter" value="Chapter 9"> <label for="chapter9">9. Mechanical Properties of Fluids</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter10" name="chapter" value="Chapter 10"> <label for="chapter10">10. Thermal Properties of Matter</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter11" name="chapter" value="Chapter 11"> <label for="chapter11">11. Thermodynamics</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter12" name="chapter" value="Chapter 12"> <label for="chapter12">12. Kinetic Theory</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter13" name="chapter" value="Chapter 13"> <label for="chapter13">13. Oscillations</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter14" name="chapter" value="Chapter 14"> <label for="chapter14">14. Waves</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter15" name="chapter" value="Chapter 15"> <label for="chapter15">15. Electric Charge and Fields</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter16" name="chapter" value="Chapter 16"> <label for="chapter16">16. Electrostatic Potential and Capacitance</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter17" name="chapter" value="Chapter 17"> <label for="chapter17">17. Current Electricity</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter18" name="chapter" value="Chapter 18"> <label for="chapter18">18. Moving Charges and Magnetism</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter19" name="chapter" value="Chapter 19"> <label for="chapter19">19. Magnetism and Matter</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter20" name="chapter" value="Chapter 20"> <label for="chapter20">20. Electromagnetic Induction</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter21" name="chapter" value="Chapter 21"> <label for="chapter21">21. Alternating Current</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter22" name="chapter" value="Chapter 22"> <label for="chapter22">22. Electromagnetic Wave</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter23" name="chapter" value="Chapter 23"> <label for="chapter23">23. Ray Optics and Optical Instruments</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter24" name="chapter" value="Chapter 24"> <label for="chapter24">24. Wave Optics</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter25" name="chapter" value="Chapter 25"> <label for="chapter25">25. Dual Nature of Radiation and Matter</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter26" name="chapter" value="Chapter 26"> <label for="chapter26">26. Atoms</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter27" name="chapter" value="Chapter 27"> <label for="chapter27">27. Nuclei</label> </div> <div class="checkbox-item"> <input type="checkbox" id="chapter28" name="chapter" value="Chapter 28"> <label for="chapter28">28. Semiconductor Electronics, Materials, Devices and Simple Circuits</label> </div> </div> </form> <div id="message" class="hidden"></div> <div class="btn-group"> <button class="btn btn-danger" id="backToStartBtn">Back to Start</button> <button class="btn btn-success" id="generateAssignmentBtn">Generate Assignment</button> </div> </div> <div id="levelSelection" class="hidden"> <h2 class="section-title">Select Difficulty Level</h2> <p class="text-center">Choose the difficulty level for your assignment:</p> <div class="level-buttons"> <button class="btn btn-level" id="level1Btn">Level 1<br><small>NCERT Based</small></button> <button class="btn btn-level" id="level2Btn">Level 2<br><small>Higher Level</small></button> <button class="btn btn-level" id="level3Btn">Level 3<br><small>NEET Exam Level</small></button> </div> <div class="btn-group"> <button class="btn btn-danger" id="backToChaptersBtn">Back to Chapters</button> <button class="btn btn-success" id="generateFinalBtn">Generate Assignment</button> </div> </div> </div> </div> <div class="container hidden" id="generatedPaperContainer"></div> <script> // Initialize jsPDF const { jsPDF } = window.jspdf; // DOM Elements const startContainer = document.getElementById('startContainer'); const startScreen = document.getElementById('startScreen'); const physicsOptions = document.getElementById('physicsOptions'); const chapterSelection = document.getElementById('chapterSelection'); const levelSelection = document.getElementById('levelSelection'); const generatedPaperContainer = document.getElementById('generatedPaperContainer'); // Buttons const startGeneratingBtn = document.getElementById('startGeneratingBtn'); const selectPhysicsBtn = document.getElementById('selectPhysicsBtn'); const backToStartBtn = document.getElementById('backToStartBtn'); const generateAssignmentBtn = document.getElementById('generateAssignmentBtn'); const backToChaptersBtn = document.getElementById('backToChaptersBtn'); const generateFinalBtn = document.getElementById('generateFinalBtn'); const level1Btn = document.getElementById('level1Btn'); const level2Btn = document.getElementById('level2Btn'); const level3Btn = document.getElementById('level3Btn'); const fullPaperCheckbox = document.getElementById('fullPaper'); const chapterCheckboxes = document.querySelectorAll('input[name="chapter"]:not(#fullPaper)'); // Variables to store selections let selectedChapters = []; let selectedLevel = null; // Event Listeners startGeneratingBtn.addEventListener('click', showPhysicsOptions); selectPhysicsBtn.addEventListener('click', showChapters); backToStartBtn.addEventListener('click', backToStart); generateAssignmentBtn.addEventListener('click', showLevelSelection); backToChaptersBtn.addEventListener('click', backToChapters); generateFinalBtn.addEventListener('click', generateAssignment); fullPaperCheckbox.addEventListener('change', toggleChapters); // Level selection event listeners level1Btn.addEventListener('click', () => selectLevel(1)); level2Btn.addEventListener('click', () => selectLevel(2)); level3Btn.addEventListener('click', () => selectLevel(3)); // Questions database with three difficulty levels for each chapter const questions = { "Chapter 1": { level1: [ { question: "The SI unit of length is:", options: ["Meter", "Centimeter", "Kilometer", "Millimeter"], answer: "A" }, { question: "Which of the following is a fundamental unit?", options: ["Newton", "Joule", "Second", "Watt"], answer: "C" }, { question: "The dimensional formula for velocity is:", options: ["[LT{ ¹]", "[LT{ ²]", "[MLT{ ¹]", "[MLT{ ²]"], answer: "A" } ], level2: [ { question: "The percentage error in the measurement of mass and speed are 2% and 3% respectively. The error in the measurement of kinetic energy is:", options: ["8%", "2%", "12%", "10%"], answer: "A" }, { question: "Which of the following pairs have the same dimensions?", options: ["Torque and Work", "Angular momentum and Work", "Energy and Young's modulus", "Light year and Wavelength"], answer: "A" } ], level3: [ { question: "If energy (E), velocity (V) and time (T) are chosen as fundamental quantities, the dimensional formula for surface tension will be:", options: ["[EV{ ²T{ ²]", "[E{ ²V{ ¹T{ ³]", "[EV{ ¹T{ ²]", "[EV{ ²T{ ¹]"], answer: "A" }, { question: "A physical quantity P is related to four observables a, b, c and d as P = a³b²/"c d. The percentage errors of measurement in a, b, c and d are 1%, 3%, 4% and 2% respectively. The percentage error in the quantity P is:", options: ["13%", "15%", "17%", "21%"], answer: "A" } ] }, "Chapter 2": { level1: [ { question: "A body is moving with uniform velocity. Its acceleration is:", options: ["Zero", "Positive", "Negative", "Variable"], answer: "A" }, { question: "The area under velocity-time graph gives:", options: ["Distance", "Acceleration", "Displacement", "Speed"], answer: "C" } ], level2: [ { question: "A car accelerates from rest at a constant rate ± for some time and then decelerates at a constant rate ² to come to rest. If the total time elapsed is t, the maximum velocity acquired by the car is:", options: ["(±²/(±+²))t", "((±+²)/±²)t", "(±²t/(±+²))", "(±+²)t/±²"], answer: "C" } ], level3: [ { question: "A particle starts from rest with constant acceleration. The ratio of space-average velocity to the time-average velocity is:", options: ["1:2", "2:1", "3:2", "2:3"], answer: "D" } ] }, "Chapter 3": { level1: [ { question: "The path of a projectile is:", options: ["Straight line", "Parabola", "Circle", "Hyperbola"], answer: "B" }, { question: "The horizontal range of a projectile is maximum when the angle of projection is:", options: ["30°", "45°", "60°", "90°"], answer: "B" } ], level2: [ { question: "A projectile is fired at an angle of 45° with the horizontal. The elevation angle of the projectile at its highest point as seen from the point of projection is:", options: ["60°", "tan{ ¹(1/2)", "tan{ ¹("3/2)", "45°"], answer: "B" } ], level3: [ { question: "A particle is projected from a point O with velocity u in a direction making an angle ± with the horizontal. At any instant its position is at point P at right angles to the initial direction of projection. Its velocity at point P is:", options: ["u tan ±", "u cot ±", "u cos ±", "u sin ±"], answer: "B" } ] }, // More chapters would follow the same pattern... // For brevity, I'm showing only a few chapters. In a complete implementation, all 28 chapters would be included. "Chapter 28": { level1: [ { question: "In an n-type semiconductor, the majority charge carriers are:", options: ["Holes", "Electrons", "Both holes and electrons", "None of these"], answer: "B" }, { question: "A p-n junction diode conducts when it is:", options: ["Forward biased", "Reverse biased", "Unbiased", "None of these"], answer: "A" } ], level2: [ { question: "The current gain ² of a transistor is 50. The input resistance of the transistor when used in the common emitter configuration is 1 k©. The peak value of the collector alternating current for an input peak voltage of 0.01 V is:", options: ["100 ¼A", "0.01 mA", "0.25 mA", "500 ¼A"], answer: "D" } ], level3: [ { question: "In the circuit shown, the current I through the battery is:", options: ["1 A", "2 A", "3 A", "4 A"], answer: "B" } ] } }; // For demonstration, I'll add placeholder questions for all chapters // In a real implementation, each chapter would have proper questions for all three levels const chapterNames = [ "Units and Measurement", "Motion in a Straight Line", "Motion in a Plane", "Laws of Motion", "Work, Energy and Power", "System of Particles and Rotational Motion", "Gravitation", "Mechanical Properties of Solids", "Mechanical Properties of Fluids", "Thermal Properties of Matter", "Thermodynamics", "Kinetic Theory", "Oscillations", "Waves", "Electric Charge and Fields", "Electrostatic Potential and Capacitance", "Current Electricity", "Moving Charges and Magnetism", "Magnetism and Matter", "Electromagnetic Induction", "Alternating Current", "Electromagnetic Wave", "Ray Optics and Optical Instruments", "Wave Optics", "Dual Nature of Radiation and Matter", "Atoms", "Nuclei", "Semiconductor Electronics, Materials, Devices and Simple Circuits" ]; // Fill in placeholder questions for all chapters for (let i = 1; i <= 28; i++) { const chapterKey = `Chapter ${i}`; if (!questions[chapterKey]) { questions[chapterKey] = { level1: [ { question: `Level 1 question for ${chapterNames[i-1]}`, options: ["Option A", "Option B", "Option C", "Option D"], answer: "A" }, { question: `Another Level 1 question for ${chapterNames[i-1]}`, options: ["Option A", "Option B", "Option C", "Option D"], answer: "B" } ], level2: [ { question: `Level 2 question for ${chapterNames[i-1]}`, options: ["Option A", "Option B", "Option C", "Option D"], answer: "C" }, { question: `Another Level 2 question for ${chapterNames[i-1]}`, options: ["Option A", "Option B", "Option C", "Option D"], answer: "D" } ], level3: [ { question: `Level 3 question for ${chapterNames[i-1]}`, options: ["Option A", "Option B", "Option C", "Option D"], answer: "A" }, { question: `Another Level 3 question for ${chapterNames[i-1]}`, options: ["Option A", "Option B", "Option C", "Option D"], answer: "B" } ] }; } } function getRandomQuestions(chapters, level, count) { try { let allQuestions = []; chapters.forEach(chapter => { if (questions[chapter] && questions[chapter][`level${level}`]) { allQuestions = allQuestions.concat(questions[chapter][`level${level}`]); } }); allQuestions = allQuestions.sort(() => Math.random() - 0.5); return allQuestions.slice(0, count); } catch (error) { console.error("Error in getRandomQuestions:", error); return []; } } function showPhysicsOptions() { startScreen.classList.add('hidden'); physicsOptions.classList.remove('hidden'); } function showChapters() { physicsOptions.classList.add('hidden'); chapterSelection.classList.remove('hidden'); } function showLevelSelection() { // Get selected chapters selectedChapters = fullPaperCheckbox.checked ? Object.keys(questions) : Array.from(document.querySelectorAll('input[name="chapter"]:checked')).map(cb => cb.value); if (selectedChapters.length === 0) { alert("Please select at least one chapter!"); return; } chapterSelection.classList.add('hidden'); levelSelection.classList.remove('hidden'); } function selectLevel(level) { // Remove selected class from all level buttons level1Btn.classList.remove('selected'); level2Btn.classList.remove('selected'); level3Btn.classList.remove('selected'); // Add selected class to the clicked button document.getElementById(`level${level}Btn`).classList.add('selected'); selectedLevel = level; } function toggleChapters() { chapterCheckboxes.forEach(cb => cb.disabled = fullPaperCheckbox.checked); } function backToStart() { generatedPaperContainer.classList.add('hidden'); startContainer.classList.remove('hidden'); chapterSelection.classList.add('hidden'); levelSelection.classList.add('hidden'); startScreen.classList.remove('hidden'); } function backToChapters() { levelSelection.classList.add('hidden'); chapterSelection.classList.remove('hidden'); } function generateAssignment() { try { if (!selectedLevel) { alert("Please select a difficulty level!"); return; } console.log("Generating assignment..."); // Hide start container and show assignment container startContainer.classList.add('hidden'); levelSelection.classList.add('hidden'); generatedPaperContainer.classList.remove('hidden'); generatedPaperContainer.innerHTML = ''; const chapterNames = selectedChapters.map(ch => { if (ch === "Full Paper") return "Full Syllabus"; const label = document.querySelector(`label[for="${ch.toLowerCase()}"]`); return label ? ch + ". " + label.textContent.split(". ")[1] : ch; }).join(", "); console.log("Chapter names:", chapterNames); // Get random questions - 45 MCQs total const mcqs = getRandomQuestions(selectedChapters, selectedLevel, 45); console.log("Questions retrieved:", { mcqs }); let questionNumber = 1; // Create assignment content let paperContent = ` <div class="header"> <h2>NEET Physics Assignment</h2> <h3>${selectedChapters.length === Object.keys(questions).length ? "Full Syllabus" : chapterNames}</h3> <p>Level ${selectedLevel} - ${selectedLevel === 1 ? "NCERT Based" : selectedLevel === 2 ? "Higher Level" : "NEET Exam Level"}</p> </div> <div class="content-area"> <div class="instructions"> <p><strong>Instructions:</strong></p> <ol> <li>This assignment contains 45 Multiple Choice Questions (MCQs).</li> <li>Each question has four options with only one correct answer.</li> <li>Choose the most appropriate answer.</li> <li>Time: 60 minutes</li> </ol> </div> <div class="question-section"> <div class="section-heading">Multiple Choice Questions</div> `; // Add MCQs mcqs.forEach((mcq, index) => { paperContent += ` <div class="question"> <div class="question-text">${questionNumber}. ${mcq.question}</div> <div class="option">A. ${mcq.options[0]}</div> <div class="option">B. ${mcq.options[1]}</div> <div class="option">C. ${mcq.options[2]}</div> <div class="option">D. ${mcq.options[3]}</div> </div> `; questionNumber++; }); // Add answer sheet paperContent += ` </div> <div class="answer-sheet"> <h3 class="section-title">Answer Key</h3> <table class="answer-table"> <thead> <tr> <th>Question No.</th> <th>Answer</th> <th>Question No.</th> <th>Answer</th> <th>Question No.</th> <th>Answer</th> </tr> </thead> <tbody> `; // Add answers in groups of 3 for (let i = 0; i < mcqs.length; i += 3) { paperContent += `<tr>`; for (let j = 0; j < 3; j++) { if (i + j < mcqs.length) { paperContent += `<td>${i + j + 1}</td><td>${mcqs[i + j].answer}</td>`; } else { paperContent += `<td></td><td></td>`; } } paperContent += `</tr>`; } paperContent += ` </tbody> </table> </div> <div class="action-buttons"> <button class="btn btn-primary" id="printBtn"><i class="fas fa-print"></i> Print Assignment</button> <button class="btn btn-success" id="downloadBtn"><i class="fas fa-download"></i> Download as PDF</button> <button class="btn btn-danger" id="newAssignmentBtn"><i class="fas fa-plus"></i> New Assignment</button> </div> </div> `; generatedPaperContainer.innerHTML = paperContent; // Add event listeners to the new buttons document.getElementById('printBtn').addEventListener('click', printAssignment); document.getElementById('downloadBtn').addEventListener('click', downloadPDF); document.getElementById('newAssignmentBtn').addEventListener('click', backToStart); console.log("Assignment generated successfully"); } catch (error) { console.error("Error generating assignment:", error); alert("An error occurred while generating the assignment. Please try again."); } } function printAssignment() { window.print(); } async function downloadPDF() { const element = document.getElementById('generatedPaperContainer'); // Create a temporary div with optimized settings const tempDiv = document.createElement('div'); tempDiv.style.position = 'absolute'; tempDiv.style.left = '-9999px'; tempDiv.style.width = '794px'; // A4 width in pixels (210mm) tempDiv.style.backgroundColor = 'white'; tempDiv.style.padding = '20px'; tempDiv.innerHTML = element.innerHTML; document.body.appendChild(tempDiv); try { const pdf = new jsPDF('p', 'mm', 'a4'); const pageWidth = pdf.internal.pageSize.getWidth() - 25.4; // 0.5" margins const pageHeight = pdf.internal.pageSize.getHeight() - 25.4; // Split content into pages let position = 12.7; // Start with 0.5" top margin let remainingHeight = tempDiv.scrollHeight; let pageNum = 1; while (remainingHeight > 0) { // Capture the current page section const canvas = await html2canvas(tempDiv, { scale: 1.5, windowHeight: pageHeight * 3.78, // mm to px windowWidth: pageWidth * 3.78, y: position * 3.78, // mm to px height: pageHeight * 3.78, useCORS: true, backgroundColor: '#ffffff', logging: false }); const imgData = canvas.toDataURL('image/jpeg', 0.92); // Add page to PDF if (pageNum > 1) { pdf.addPage('a4', 'portrait'); } pdf.addImage(imgData, 'JPEG', 12.7, 12.7, pageWidth, canvas.height * pageWidth / canvas.width); position += pageHeight; remainingHeight -= pageHeight * 3.78; // px pageNum++; } // Save PDF pdf.save('NEET_Physics_Assignment.pdf'); console.log("PDF saved successfully"); } catch (error) { console.error('PDF generation error:', error); alert('Error generating PDF. Please check the console for details.'); // Remove temporary div if it exists const tempDiv = document.querySelector('.temp-pdf-container'); if (tempDiv) { document.body.removeChild(tempDiv); } } } </script> </body> </html>