Hi, I'm Marcos, an independent digital creator from Venezuela. I build interactive web experiences with plain HTML, CSS, and JavaScript, and I share my journey one project at a time. Today's project is a little Christmas game: you decorate a tree or assemble a nativity scene by dragging ornaments and characters onto a stage, and the app scores how correct your arrangement is.
You can play it right here: https://margus20.github.io/decoracion-navidad/
The idea behind the scoring
The trick of the whole game is that it does not check for a fixed picture. It checks for relationships. Each piece has a position stored as a percentage of the stage, and the rules are spatial: the star must be near the top, the nutcracker near the feet of the tree, the ornaments must not pile on top of each other, and the visual order from top to bottom has to be coherent. The same idea powers the nativity: baby Jesus in the crib, the crib inside the manger, the star above it, Mary and Joseph close to the scene, the animals on the ground and balanced on opposite sides.
// A rule is just a boolean over the pieces' positions function ruleStarOnTop(figures) { const star = figures.find(f => f.dataset.personaje === 'estrella'); if (!star) return false; return parseFloat(star.dataset.y) < 25; // top quarter of the stage } Each rule contributes points, and when the total reaches one hundred the game celebrates. I love this approach because it rewards understanding instead of memorizing coordinates, and it makes the same engine work for two different scenes with different rule sets.
The bilingual system, and the cache trap it exposed
The game switches between Spanish and English with a small dictionary I wrote myself, no i18n library. The interesting part is the color palette for the bow, the bulb, and the valance. At first the panel translated everything except the color names, and the title showed up as a raw key in capital letters. The culprit was not the code, it was the browser cache: one file had loaded fresh while another was still the old version in memory, so the two files were out of sync.
The fix that ended the whole fight was to stop depending on a second file for the palette. I gave the palette its own tiny dictionary inside the file that draws it, so the translation lives right next to the UI that needs it.
const PALETA_EN = { rojo: 'Red', amarillo: 'Yellow', anaranjado: 'Orange', azul: 'Blue', morado: 'Purple', plateado: 'Silver', original: 'Original' }; function tColor(nombreOriginal) { const clave = nombreOriginal.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, ''); return PALETA_EN[clave] || nombreOriginal; } The lesson: when a feature looks broken in a way that contradicts your code, suspect the cache before you suspect the logic. Bumping a version query on the script tag, like ?v=23, is the cheapest way to force a fresh download.
Pinch to resize, without losing drag
Pieces are dragged with one finger or the mouse, but I wanted people to also grow and shrink a piece with a two-finger pinch, the way you would expect on a phone. The catch is that the same touch handler must decide in real time whether two fingers mean "pinch" or one finger means "drag". I track the distance between the two touch points and scale the zoom relative to the starting distance, clamped to the same limits the sliders use.
function distanciaDosDedos(e) { const t = e.touches; return Math.hypot(t[0].clientX - t[1].clientX, t[0].clientY - t[1].clientY); } // in the move handler, when two fingers are down: let nuevoZoom = zoomPinchInicial * (distanciaDosDedos(e) / distPinchInicial); nuevoZoom = Math.max(40, Math.min(300, nuevoZoom)); elemento.dataset.zoom = nuevoZoom; The sliders update themselves to reflect the new size, so touch and the control panel never disagree.
Music that survives page changes
The game has three pages: a cover, the tree, and the nativity. The problem with music on a multi-page site is that every time you navigate, the browser tears down the old page and the audio stops. The solution is to remember the play state in localStorage. When a page loads, it reads that flag and resumes automatically if the user had left the music on.
// save the state whenever the user toggles it localStorage.setItem('musicaActiva', activo ? 'true' : 'false'); // on page load, resume if it was on const estado = localStorage.getItem('musicaActiva') === 'true'; if (estado) setTimeout(reproducir, 300); One more detail I learned the hard way: the audio files I first used were really video files renamed to .mp3, and the browser refused them with a "no supported format" error. Renaming an extension does not change what is inside the file. Switching to real audio sources fixed it instantly.
Protecting the user from an accidental exit
Because a game has progress, I added a confirmation before leaving. The browser's own exit dialog is the one you see when closing a tab or reloading, and by design it cannot be styled or translated, so I built my own modal for the in-game "back" button instead, matching the game's gold-on-dark palette and the Bebas Neue font, and reading the current language.
const TXT = { es: { titulo: 'CONFIRMAR SALIDA', cancelar: 'CANCELAR', aceptar: 'SALIR' }, en: { titulo: 'LEAVE GAME?', cancelar: 'CANCEL', aceptar: 'LEAVE' } }; The honest takeaway: some dialogs belong to the browser and you cannot dress them up. The right move is to control the moments you can control, like the buttons inside your own page.
What I learned
This project taught me more than a tutorial ever did, because every bug was a real constraint. The cache desync taught me to isolate dependencies. The fake mp3 taught me that a file is its bytes, not its name. The pinch gesture taught me that a touch handler can be a state machine, not just a single action. And the exit dialog taught me to accept the limits of the platform and design around them.
If you want to play with it, the source is on my GitHub and the live demo is the link above. If you build your own scoring rules for a different scene, or you improve the flame or the drag, I would love to hear about it in the comments. Thanks for reading, and happy building from Venezuela.



