This code creates a simple memory card matching game using JavaScript, HTML,
and CSS. The goal is to flip two cards at a time and find all the matching pairs.
How to Use?
Add the provided HTML structure for the cards, style them with CSS, and connect
the JavaScript logic. The script handles shuffling, flipping cards, and checking
for matches — no libraries needed.
Credits
Based on classic JavaScript memory game logic and DOM manipulation techniques.
Modified to be more interactive and responsive.
<div id="picbox">
<span id="boxbuttons">
<span class="button">
<span id="counter">0</span>
Clicks
</span>
<span class="button">
<a onclick="ResetGame();">Reset</a>
</span>
</span>
<div id="boxcard"></div>
</div>
* {
margin: 0;
padding: 0;
}
body {
font: 18px Verdana;
color: #FFF;
background: #CCC;
}
#picbox {
margin: 0px auto;
width: 640px;
}
#boxcard {
z-index: 1;
margin: 10px 0 0;
}
#boxcard div{
float: left;
width: 100px;
height: 100px;
margin: 5px;
padding: 5px;
border: 4px solid #EE872A;
cursor: pointer;
border-radius: 10px;
box-shadow: 0 1px 5px rgba(0,0,0,.5);
background: #B1B1B1;
z-index: 2;
}
#boxcard div img {
display: none;
border-radius: 10px;
z-index: 3;
}
#boxbuttons {
text-align: center;
margin: 20px;
display: block;
}
#boxbuttons .button {
text-transform: uppercase;
background: #EE872A;
padding: 5px 10px;
margin: 5px;
border-radius: 10px;
cursor: pointer;
}
#boxbuttons .button:hover {
background: #999;
}
var BoxOpened = "";
var ImgOpened = "";
var Counter = 0;
var ImgFound = 0;
var Source = "#boxcard";
var ImgSource = [
"http:
"http:
"http:
"http:
"http:
"http:
"http:
"http:
"http:
"http:
];
function RandomFunction(MaxValue, MinValue) {
return Math.round(Math.random() * (MaxValue - MinValue) + MinValue);
}
function ShuffleImages() {
var ImgAll = $(Source).children();
var ImgThis = $(Source + " div:first-child");
var ImgArr = new Array();
for (var i = 0; i < ImgAll.length; i++) {
ImgArr[i] = $("#" + ImgThis.attr("id") + " img").attr("src");
ImgThis = ImgThis.next();
}
ImgThis = $(Source + " div:first-child");
for (var z = 0; z < ImgAll.length; z++) {
var RandomNumber = RandomFunction(0, ImgArr.length - 1);
$("#" + ImgThis.attr("id") + " img").attr("src", ImgArr[RandomNumber]);
ImgArr.splice(RandomNumber, 1);
ImgThis = ImgThis.next();
}
}
function ResetGame() {
ShuffleImages();
$(Source + " div img").hide();
$(Source + " div").css("visibility", "visible");
Counter = 0;
$("#success").remove();
$("#counter").html("" + Counter);
BoxOpened = "";
ImgOpened = "";
ImgFound = 0;
return false;
}
function OpenCard() {
var id = $(this).attr("id");
if ($("#" + id + " img").is(":hidden")) {
$(Source + " div").unbind("click", OpenCard);
$("#" + id + " img").slideDown('fast');
if (ImgOpened == "") {
BoxOpened = id;
ImgOpened = $("#" + id + " img").attr("src");
setTimeout(function () {
$(Source + " div").bind("click", OpenCard)
}, 300);
} else {
CurrentOpened = $("#" + id + " img").attr("src");
if (ImgOpened != CurrentOpened) {
setTimeout(function () {
$("#" + id + " img").slideUp('fast');
$("#" + BoxOpened + " img").slideUp('fast');
BoxOpened = "";
ImgOpened = "";
}, 400);
} else {
$("#" + id + " img").parent().css("visibility", "hidden");
$("#" + BoxOpened + " img").parent().css("visibility", "hidden");
ImgFound++;
BoxOpened = "";
ImgOpened = "";
}
setTimeout(function () {
$(Source + " div").bind("click", OpenCard)
}, 400);
}
Counter++;
$("#counter").html("" + Counter);
if (ImgFound == ImgSource.length) {
$("#counter").prepend('<span id="success">You Found All Pictues With </span>');
}
}
}
$(function () {
for (var y = 1; y < 3; y++) {
$.each(ImgSource, function (i, val) {
$(Source).append("<div id=card" + y + i + "><img src=" + val + " />");
});
}
$(Source + " div").click(OpenCard);
ShuffleImages();
});
$nomention
$onlyIf[$guildID!=;]
$allowUserMentions[]
$reply
$if[$message==]
Usage: !buy {item} {amount}
$else
$var[price1;$multi[1000;$message[2;amount]]]
$var[price2;$multi[5000;$message[2;amount]]]
$var[price3;$multi[10000;$message[2;amount]]]
$c[add more price variables as you add more items and the number inside multi is the actual price btw]
$if[$toLowercase[$message[1;item]==item1]]
$onlyIf[$getVar[clicker;$authorID]>=$var[price1];You don't have enough clicks to buy this item.]
$description[Successfully bought `$message[2;amount]` Item 1(s).]
$color[#2F3136]
$setVar[item1;$sum[$getVar[item1;$authorID];$message[2;amount]];$authorID]
$setVar[clicker;$sub[$getVar[clicker;$authorID];$var[price1]];$authorID]
$elseif[$toLowercase[$message[1;item]==item2]]
$onlyIf[$getVar[clicker;$authorID]>=$var[price2];You don't have enough clicks to buy this item.]
$description[Successfully bought `$message[2;amount]` Item2(s).]
$color[#2F3136]
$var[temp-item2;$multi[$message[2;amount];2]]
$c[The 2 at the end here is because this item gives a +2 multiplier]
$setVar[item2;$sum[$getVar[item2;$authorID];$var[temp-item2]];$authorID]
$setVar[clicker;$sub[$getVar[clicker;$authorID];$var[price2]];$authorID]
$elseif[$toLowercase[$message[1;item]==item3]]
$onlyIf[$getVar[clicker;$authorID]>=$var[price3];You don't have enough clicks to buy this item.]
$description[Successfully bought `$message[2;amount]` Item3(s).]
$color[#2F3136]
$var[temp-item3;$multi[$message[2;amount];3]]
$c[The 3 at the end here is because this item gives a +2 multiplier]
$setVar[item3;$sum[$getVar[item3;$authorID];$var[temp-item3]];$authorID]
$setVar[clicker;$sub[$getVar[clicker;$authorID];$var[price3]];$authorID]
$endif
$endif