re: Monster Game Vanilla JS Accademy VIEW POST


Thanks for the post! Consider adding a paragraph or two explaining the game. It will help when people are searching articles.

Also, you can use the liquid tag {%github https://github.com/GiandomenicoRiceputi/Monster-Game %} to embed your repository link. It will look like this


In this project I am going to play around method in order to shuffling an array (The monsters).
For this I use:

 * Randomly shuffle an array
 * https://stackoverflow.com/a/2450976/1293256
 * @param  {Array} array The array to shuffle
 * @return {String}      The first item in the shuffled array
var shuffle = function (array) {

    var currentIndex = array.length;
    var temporaryValue, randomIndex;

    // While there remain elements to shuffle...
    while (0 !== currentIndex) {
        // Pick a remaining element...
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;

        // And swap it with the current element.
        temporaryValue = array[currentIndex];
        array[currentIndex] = array[randomIndex];
        array[randomIndex] = temporaryValue;

    return array;


Don't forget the accessibility and add the alt text to the images. I use the Element.closest() method to get the closest parent up the DOM tree.
I use the simple math (++) to help me in the win or lose function.


yes and a readme for the github would be a great addition :)

code of conduct - report abuse