Housie Ticket Generator

Updated & refreshed content:

Updated & refreshed content:

Housie Ticket Generator

// Function to generate the housie ticket function generateTicket() { // Show ticket section document.getElementById(‘ticketSection’).style.display = ‘block’; // Create an array to store ticket numbers var numbers = []; var ticket = document.getElementById(‘ticket’); ticket.innerHTML = ”; // Clear previous ticket if any // Generate 15 unique numbers (15 random numbers between 1 and 90) while (numbers.length < 15) { var randomNum = Math.floor(Math.random() * 90) + 1; if (!numbers.includes(randomNum)) { numbers.push(randomNum); } } // Fill the ticket grid with random numbers for (var i = 0; i < 15; i++) { var cell = document.createElement('div'); cell.textContent = numbers[i]; cell.style.padding = '20px'; cell.style.fontSize = '18px'; cell.style.textAlign = 'center'; cell.style.backgroundColor = '#fff'; cell.style.borderRadius = '8px'; cell.style.border = '1px solid #F7E23E'; cell.style.fontWeight = 'bold'; ticket.appendChild(cell); } // Formatting the ticket grid for a better look document.getElementById('ticket').style.gridTemplateColumns = 'repeat(5, 1fr)'; } // Function to download the ticket as an image (screenshot) function downloadTicket() { // Create a canvas and draw the ticket into it for download var ticket = document.getElementById('ticket'); var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); // Adjust canvas size to match the ticket dimensions canvas.width = ticket.offsetWidth; canvas.height = ticket.offsetHeight; // Draw the ticket on the canvas ctx.fillStyle = '#ffffff'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.font = 'bold 18px Arial'; ctx.fillStyle = '#333'; var cells = ticket.getElementsByTagName('div'); for (var i = 0; i < cells.length; i++) { var x = (i % 5) * 60 + 20; // Adjusting cell position var y = Math.floor(i / 5) * 60 + 20; ctx.fillText(cells[i].textContent, x, y); } // Create an image URL from the canvas var imageUrl = canvas.toDataURL('image/png'); // Trigger the download var link = document.createElement('a'); link.href = imageUrl; link.download = 'housie_ticket.png'; link.click(); }

Check out latest updates & share!

Check out latest updates & share!