Skip to content

Instantly share code, notes, and snippets.

@angusgrant
Last active November 7, 2022 19:53
Show Gist options
  • Save angusgrant/f05c09274f50a17f9d4a018b04f79513 to your computer and use it in GitHub Desktop.
Save angusgrant/f05c09274f50a17f9d4a018b04f79513 to your computer and use it in GitHub Desktop.
vanilla JS week 4 exersise 1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Monsters!</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
margin: 0 auto;
max-width: 40em;
width: 88%;
}
/**
* A simple grid layout
*/
.row {
display: grid;
grid-template-columns: auto auto auto;
text-align: center;
}
.grid {
min-height: 6em;
padding: 1em;
}
/**
* Make sure images scale
*/
img {
height: auto;
max-width: 100%;
}
</style>
</head>
<body>
<h1>Monsters!</h1>
<div id="app"></div>
<footer>
<hr>
<p class="text-small text-muted">Icons by <a href="https://thenounproject.com/term/door/311732/">Jamie Dickinson</a>, <a href="https://thenounproject.com/term/monster/184225/">Nicky Knicky</a>, <a href="https://thenounproject.com/term/monster/1510400/">Alvaro Cabrera</a>, <a href="https://thenounproject.com/term/monster/28460/">Eliricon</a>, <a href="https://thenounproject.com/term/monster/82823/">April Yang</a>, <a href="https://thenounproject.com/term/monster/1062009/">tk66</a>, <a href="https://thenounproject.com/term/monster/24990/">Alex WaZa</a>, <a href="https://thenounproject.com/term/monster/37212/">Husein Aziz</a>, <a href="https://thenounproject.com/term/monster/2236082">iconcheese</a>, and <a href="https://thenounproject.com/term/socks/38451/">Yazmin Alanis</a>.</p>
</footer>
<script>
// The monsters and socks if I wanted to spend longer on this problem I would have converted it to an array of objects
let monsters = [
'<img src="monster1.svg" alt="yellow monster small one eye">',
'<img src="monster2.svg" alt="yellow monster large one eye">',
'<img src="monster3.svg" alt="green monster two eyes looks like a venus fly trap">',
'<img src="monster4.svg" alt="red monster four arms like a tree truck">',
'<img src="monster5.svg" alt="green monster small one eye">',
'<img src="monster6.svg" alt="green monster large kinda triangle shaped">',
'<img src="monster7.svg" alt="purple monster with one eye and two tentacles">',
'<img src="monster8.svg" alt="purple monster small one eye no arms!">',
'<img src="monster9.svg" alt="blue monster monster bug like with wings">',
'<img src="monster10.svg" alt="blue monster with eyes on stalks">',
'<img src="monster11.svg" alt="grey monster looks a bit like chewbacca from star wars">',
'<img src="sock.svg" alt="this is just a couple of silver / white socks">'
];
//put array of images in a random order and update the monsters var!
monsters = shuffle(monsters);
const siteAppendPoint = document.querySelector('#app');
siteAppendPoint.innerHTML = `<div class="row">
${monsters.map(function(monster) {
return `<div class="grid">${monster}</div>`
}).join('')};
</div>`
function shuffle (array) {
let currentIndex = array.length;
let 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;
}
// Your code goes here...
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
<svg width="85" height="92" xmlns="http://www.w3.org/2000/svg" aria-labelledby="title-monster2"><title id="title-monster2">Monster 2</title><g fill-rule="nonzero" fill="#daa829"><circle cx="40.748" cy="20.232" r="3.029"/><path d="M84.473 65.435c.171.896-.541 1.323-1.318 1.445-.626.098-2.653.75-2.496-1.687.278.744.885 1.212 1.721 1.002 1.383-.347 2.259-1.395 1.846-2.318-.191.612-.574 1.468-1.626 1.456-.825-.011-1.789.208-1.581-1.534.042.482.263.771.643.787.657.029 1.988-.359 1.809-1.31-.544.994-.902.812-1.38.772-.366-.03-.78-.432-.571-1.687 2.896-10.971 2.458-25.435-.727-37.033.461-1.509.705-3.082.705-4.698C81.498 9.267 69.447.056 54.583.056c-3.771 0-7.361.594-10.62 1.665a36.79 36.79 0 0 0-3.313-.148c-3.35 0-6.542.445-9.455 1.25a36.584 36.584 0 0 0-3.529-.17C12.386 2.654 0 12.089 0 23.727c0 3.187.929 6.208 2.592 8.916C.721 45.372 2.437 61.06 7.486 71.807l.001.009.016.029c.295.625.599 1.237.917 1.828 1.199 1.955 2.996 1.09 3.929-.441.932-1.531-.134-1.863-.6-2.33.69.594.399 1.373-.133 1.951-.43.467-1.61 2.238-3.003.232.681.41 1.447.399 1.971-.286.865-1.132.898-2.497 0-2.963.232.6.466 1.507-.366 2.151-.652.506-1.269 1.276-2.192-.216.333.352.686.439.994.216.533-.387 1.332-1.519.599-2.151.193 1.117-.199 1.198-.599 1.465-.344.229-1.032.137-1.738-1.444C3.508 56.239 3.403 44.33 4.447 35.19c4.933 5.785 13.487 9.611 23.217 9.611.482 0 .96-.01 1.437-.027 1.696 4.879 7.237 8.518 13.917 8.796-.372 3.512-1.798 11.517-1.705 22.591.1 11.818-1.098 14.248-4.727 15.779 1.064 0 4.594.135 7.259 0-2.064-12.826-1.427-30.77-.235-38.354.078.001.156.004.235.004.638 0 1.267-.031 1.884-.091 1.199 7.534 1.851 25.564-.221 38.441 2.665.135 6.192 0 7.259 0-3.629-1.531-4.828-3.961-4.729-15.779.095-11.226-1.371-19.293-1.718-22.729 7.263-.928 12.804-5.862 12.804-11.811 0-.238-.009-.472-.026-.706 9.31-1.204 16.994-6.059 20.441-12.571 2.092 8.642 3.365 19.92 1.52 33.287v.001a42.83 42.83 0 0 0-.486 1.857l-.004.006-.005.035c-.16.673-.302 1.341-.421 2-.279 2.278 1.665 2.719 3.348 2.101 1.684-.616 1.057-1.541.982-2.196zM46.15 7.877c-2.26-1.721-10.106-2.863-14.328 1.862C34.653 3.703 44.2 4.742 46.15 7.877zm-5.402 2.735c5.314 0 9.621 4.307 9.621 9.62 0 5.313-4.307 9.62-9.621 9.62-5.312 0-9.62-4.307-9.62-9.62a9.62 9.62 0 0 1 9.62-9.62zM28.737 39.808c.745.089 1.55.141 2.402.16.092-1.585.792-2.479 1.701-3.208 1.026.942 1.137 2.393 1.147 3.167.358-.016.72-.037 1.087-.061.341-.891.928-1.477 1.623-1.967.499.517.746 1.153.864 1.755a78.611 78.611 0 0 0 1.915-.219c.292-.478.676-.862 1.106-1.209.312.286.539.617.707.963.72-.105 1.441-.217 2.157-.336.172-.228.362-.442.568-.644.187.138.348.295.49.463 1.555-.273 3.078-.571 4.521-.881.078-.251.187-.502.339-.741.309.136.604.29.881.475a98.614 98.614 0 0 0 1.916-.447 3.171 3.171 0 0 1 .269-1.378c.635.175 1.229.427 1.755.868.216-.057.424-.113.629-.17-.217-.761-.496-2.129.184-3.291 1.062.419 1.979 1.049 2.538 2.476.738-.249 1.285-.466 1.589-.638-5.691 9.723-25.103 7.658-30.388 4.863z"/></g></svg>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment