/* Each monster (or sock) has a matching SVG in the source code. For example, there’s a monster3 in the array, and a monster3.svg in the source code. Shuffle the array of monsters, and render the matching SVG files into the #app element. */
/* If the user finds the sock before they’ve found all of the monsters, display a message letting them know they lost. If they find all of the monsters, display a message letting them know they’ve won. Either way, show a button that they can click to play again. */
const render = function () { app.innerHTML = '<p>Click a door to reveal a monster. Try not to find the sock.</p><div class="row">' + monsters.map(monster => { return (` <div class="grid" aria-live="polite"><button class="show_button" data-id="${monster}"><img alt= "Click this picture of door to see monster" src="../img/door.svg"/></button></div> `) }).join('') + '</div>'; };
const shuffleArr = function (arr) { var currentIndex = arr.length; var temporaryValue, randomIndex;
/* Use state-based UI to create the timer, and countdown from 60 seconds to 0 once a second. When the timer is done, stop the countdown and provide a way for users to start it again. */
const timeValue = 6; const Rue = function (selector, options) { this.elem = document.querySelector(selector); this.data = options.data; this.template = options.template; }; Rue.prototype.render = function () { this.elem.innerHTML = this.template(this.data); }; Rue.prototype.restartTimer = function () { this.data.time = timeValue; app.timer() } Rue.prototype.stopTimer = function () { this.elem.innerHTML = `<h2>It's over, start again:</h2><button onclick="app.restartTimer()" class="button">Start Again</button>` } Rue.prototype.timer = function () { const intervalCount = window.setInterval(function () { if(!app) return; app.data.time-- app.render(); if (app.data.time < 1) { window.clearInterval(intervalCount) app.stopTimer() } }, 1000); app.render(); }; const app = new Rue('#app', { data: { time: timeValue, }, template: function (props) { if (!props) return; let html = `<h2>You've got only <span class="counter">${props.time}</span> seconds!</h2>`; return html; } }) app.timer();