JavaScript App

Pig Game | 2024

  • JavaScript

A "Pig" game written as part of a JavaScript course. JavaScript, my own. CSS and HTML by Jonas Schmedtmann

Converted to use Parcel as a bundler (as with all my projects), so I needed to convert to ES6 modules in order for dynamic images to work. This allowed me to import the images, which were not explicitly referenced in code. I then used a switch to change between images for each dice roll, rather than dynamically change the image filename itself, as per my course.

//import images
import dice1 from '../images/dice-1.png';
// other images 2-6

let diceSrc;
switch (dice) {
  case 1:
    diceSrc = dice1;
    break;
// other cases 2-6
}

diceEl.src = diceSrc;

Link to Website

CONTACT