Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const modal = document.getElementById('modal');
+ const experimentDetails = document.querySelector('.experiment-details');
+ const closeBtn = document.querySelector('.close-btn');
+
+ const experiments = {
+ rainbow: {
+ title: 'Rainbow in a Glass',
+ materials: ['Glass of water', 'Mirror', 'White paper', 'Sunlight'],
+ steps: [
+ 'Fill a glass with water',
+ 'Place mirror in the water at an angle',
+ 'Place in direct sunlight',
+ 'Hold white paper to catch the rainbow'
+ ]
+ },
+ refraction: {
+ title: 'Light Refraction Pencil',
+ materials: ['Glass of water', 'Pencil'],
+ steps: [
+ 'Fill a glass with water',
+ 'Place pencil in water at an angle',
+ 'Observe the optical illusion'
+ ]
+ },
+ spectroscope: {
+ title: 'DIY Spectroscope',
+ materials: ['CD or DVD', 'Cardboard box', 'Scissors', 'Tape'],
+ steps: [
+ 'Cut a slit in the box',
+ 'Place CD at 45° angle',
+ 'Make viewing window',
+ 'Point at light source'
+ ]
+ },
+ shadow: {
+ title: 'Shadow Theater',
+ materials: ['Flashlight', 'White wall or sheet', 'Various objects'],
+ steps: [
+ 'Darken the room',
+ 'Position light source',
+ 'Create shadows with objects',
+ 'Experiment with distances'
+ ]
+ }
+ };
+
+ document.querySelectorAll('.experiment-btn').forEach(button => {
+ button.addEventListener('click', () => {
+ const experiment = experiments[button.dataset.experiment];
+ let content = `
+
${experiment.title}
+
Materials Needed:
+
${experiment.materials.map(item => `- ${item}
`).join('')}
+
Steps:
+
${experiment.steps.map(step => `- ${step}
`).join('')}
+ `;
+ experimentDetails.innerHTML = content;
+ modal.classList.remove('hidden');
+ });
+ });
+
+ closeBtn.addEventListener('click', () => {
+ modal.classList.add('hidden');
+ });
+
+ window.addEventListener('click', (e) => {
+ if (e.target === modal) {
+ modal.classList.add('hidden');
+ }
+ });
+ });