Team Ai
Apppublic

yahyaamara11/integer-explorer

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
script.js54 linesDownload Raw Back to root
1document.addEventListener('DOMContentLoaded', function() {2    // Initialize tooltips3    const tooltipTriggers = document.querySelectorAll('[data-tooltip]');4    5    tooltipTriggers.forEach(trigger => {6        trigger.addEventListener('mouseenter', function() {7            const tooltip = document.createElement('div');8            tooltip.className = 'absolute z-10 bg-gray-800 text-white text-xs rounded py-1 px-2 whitespace-nowrap';9            tooltip.textContent = this.getAttribute('data-tooltip');10            11            const rect = this.getBoundingClientRect();12            tooltip.style.top = `${rect.top - 30}px`;13            tooltip.style.left = `${rect.left + rect.width / 2}px`;14            tooltip.style.transform = 'translateX(-50%)';15            16            document.body.appendChild(tooltip);17            this._tooltip = tooltip;18        });19        20        trigger.addEventListener('mouseleave', function() {21            if (this._tooltip) {22                document.body.removeChild(this._tooltip);23                this._tooltip = null;24            }25        });26    });27 28    // Add animation classes to elements29    const animatedElements = document.querySelectorAll('.card, .feature');30    animatedElements.forEach((el, index) => {31        el.style.animationDelay = `${index * 0.1}s`;32        el.classList.add('slide-up');33    });34});35 36// Integer practice generator37function generateIntegerProblem(type) {38    const a = Math.floor(Math.random() * 20) - 10;39    const b = Math.floor(Math.random() * 20) - 10;40    41    switch(type) {42        case 'addition':43            return { problem: `${a} + ${b} = ?`, answer: a + b };44        case 'subtraction':45            return { problem: `${a} - ${b} = ?`, answer: a - b };46        case 'multiplication':47            return { problem: `${a} × ${b} = ?`, answer: a * b };48        case 'division':49            const divisor = b !== 0 ? b : 1;50            return { problem: `${a} ÷ ${divisor} = ?`, answer: Math.round(a / divisor * 100) / 100 };51        default:52            return { problem: `${a} + ${b} = ?`, answer: a + b };53    }54}