Simple memory game in JS
How do I make an simple memory game in js?
What is a simple memory game in js? How do you make a simple memory game in js? This script and codes were developed by James Barnett on 11 August 2022, Thursday.
Simple memory game in JS - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Simple memory game in JS</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>LOLCatz Memory Game</h1>
<div id = "container"></div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Simple memory game in JS - Script Codes CSS Codes
h1 { font-size: 1.5em; margin-left: 44px;
}
#container { width: 800px; }
ul { padding: 0; margin: 0;}
li { padding: 0; float: left; margin: 10px; list-style: none; outline: solid; width: 150px; height: 150px;
}
img { width: 100%; height: 100%;
}
Simple memory game in JS - Script Codes JS Codes
var images = [];
// get images, place them in an array & randomize the order
for (var i = 0; i < 8; i++) { var rand = Math.floor(Math.random() * (1200 - 900 + 1) + 900); var img = 'http://lolcat.com/images/lolcats/' + rand + '.jpg'; images.push(img); images.push(img);
}
randomizeImages();
// output images then hide them
var output = "<ol>";
for (var i = 0; i < 16; i++) { output += "<li>"; output += "<img src = '" + images[i] + "'/>"; output += "</li>";
}
output += "</ol>";
document.getElementById("container").innerHTML = output;
$("img").hide();
var guess1 = "";
var guess2 = "";
var count = 0;
$("li").click(function() { if ((count < 2) && ($(this).children("img").hasClass("face-up")) === false) { // increment guess count, show image, mark it as face up count++; $(this).children("img").show(); $(this).children("img").addClass("face-up"); //guess #1 if (count === 1 ) { guess1 = $(this).children("img").attr("src"); } //guess #2 else { guess2 = $(this).children("img").attr("src"); // since it's the 2nd guess check for match if (guess1 === guess2) { console.log("match"); $("li").children("img[src='" + guess2 + "']").addClass("match"); } // else it's a miss else { console.log("miss"); setTimeout(function() { $("img").not(".match").hide(); $("img").not(".match").removeClass("face-up"); }, 1000); } // reset count = 0; setTimeout(function() { console.clear(); }, 60000); } }
});
// randomize array of images
function randomizeImages(){ Array.prototype.randomize = function() { var i = this.length, j, temp; while ( --i ) { j = Math.floor( Math.random() * (i - 1) ); temp = this[i]; this[i] = this[j]; this[j] = temp; } }; images.randomize();
}
Developer | James Barnett |
Username | jamesbarnett |
Uploaded | August 11, 2022 |
Rating | 3.5 |
Size | 2,500 Kb |
Views | 97,152 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Time-based CSS Background | 2,664 Kb |
Simple CSS Dropdown Menu | 3,822 Kb |
Extremely simple loading animation | 1,804 Kb |
Floating Fixed Sidebar | 2,857 Kb |
Console.log output in codepen | 1,713 Kb |
Change font size using JQuery | 2,084 Kb |
HTML-only captcha | 1,630 Kb |
Progress bar for counting checkboxes | 2,268 Kb |
Custom select box | 2,323 Kb |
Search field | 2,100 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
SVG Hover Animations | Kjbrum | 10,557 Kb |
Large canvas mousemove experiment | Jibbon | 2,885 Kb |
Slider for stackoverflow | KKOKU | 3,222 Kb |
The Fly | GianlucaGuarini | 3,405 Kb |
Experiment | Toddmoy | 2,849 Kb |
CSS Letter animations | Sladix | 2,116 Kb |
Pure CSS Read More Arrow | Zephyr | 1,747 Kb |
Part 19 Bootstrap split button dropdown | Venkatesha | 1,601 Kb |
Bubble animation | Ftabor | 6,565 Kb |
A Pen by Ash | Littleginger | 2,386 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!