Click here to Skip to main content
15,917,005 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Javascript HEX game Pin
Member 1373553030-Apr-18 22:22
Member 1373553030-Apr-18 22:22 
GeneralRe: Javascript HEX game Pin
Richard MacCutchan30-Apr-18 23:05
mveRichard MacCutchan30-Apr-18 23:05 
AnswerRe: Javascript HEX game Pin
Richard MacCutchan30-Apr-18 23:04
mveRichard MacCutchan30-Apr-18 23:04 
QuestionJavaScript beginner books, wich one? Pin
Member 1378482717-Apr-18 12:38
Member 1378482717-Apr-18 12:38 
SuggestionRe: JavaScript beginner books, wich one? Pin
Blikkies18-Apr-18 0:09
professionalBlikkies18-Apr-18 0:09 
AnswerRe: JavaScript beginner books, wich one? Pin
W Balboos, GHB4-May-18 7:15
W Balboos, GHB4-May-18 7:15 
QuestionJavascript on mobile application Pin
Member 1378151915-Apr-18 22:24
Member 1378151915-Apr-18 22:24 
QuestionMaking two cards match and then disappear with JQuerry Pin
Member 137670576-Apr-18 23:09
Member 137670576-Apr-18 23:09 
Hello, I am building a JS game that consists of tiles which show a card background when you click on them, I want to make somehow that if two cards have the same image they should disappear from the deck if not they should turn to their back side again, but I am stuck on making them match. Here is my code:

The HTML:

HTML
<div class="container">
        <header>

            <h1> Memory Game
         </h1>
        </header>

        <ul class="deck" id="card-deck">
            <li></li>
        </ul>

    </div>


my Javascript:

JavaScript
<pre>//Storing the mask images


var masks = ["/images/1.jpg", "/images/2.jpg", "/images/3.jpg", "/images/4.jpg", "/images/12.jpg", "/images/6.jpg", "/images/1.jpg", "/images/2.jpg", "/images/3.jpg", "/images/4.jpg", "/images/12.jpg", "/images/6.jpg", ];

// Shuffling the array using the Fisher Yates
function shuffleMasks(masks) {
    for (var i = masks.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = masks[i];
        masks[i] = masks[j];
        masks[j] = temp;
    }
}




// Show modal when page loads and close me piece
function showModal() {
    modal.style.display = "block";
    $('#closeMe').hide().delay(10000).show('fast')
}

// Close modal after the X has been clicked
function closeModal() {
    modal.style.display = "none";
}



// JQuerry goes here

$(document).ready(function () {
    window.modal = document.getElementById('myModal');
    shuffleMasks(masks);
    console.log(masks)
        //    showModal();
    for (var i = 0; i < masks.length; i++) {
        $(".deck").append('<div class="card"> <img class="card" src="' + masks[i] + '"/></div>');

    }
    $(".deck").on('click', '.card', function () {
        var cardVisible = $('.card img:visible').length; //Get the number of visible img

        if (cardVisible >= 2) $('.card img').hide(); //If 2 or more, hide all
        var open = $('img').attr('id', 'open');

        $(this).find("img").show() //Show the image



        $(".card").on('click', function () {
            var source = $(this).find("img").attr('src')
            alert(source);
            if (source === source) {
                $('.card img').hide();
            }



        })







    })





My last function gets the src of the image and I alert so that I make sure that it get's them, but it dosen't alert once the tile has shown its front image it alerts a bunch of times, and I can't get to make my comparision right, can someone tell me what is the best way to achieve this matching and removing if the images are the same? Thanks in advance
AnswerRe: Making two cards match and then disappear with JQuerry Pin
Christian75739-Apr-18 15:47
Christian75739-Apr-18 15:47 
QuestionNewbie: how do I analyse DOM Objects? Pin
enginestar5-Apr-18 3:05
enginestar5-Apr-18 3:05 
AnswerRe: Newbie: how do I analyse DOM Objects? Pin
Richard MacCutchan5-Apr-18 4:34
mveRichard MacCutchan5-Apr-18 4:34 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
enginestar5-Apr-18 4:50
enginestar5-Apr-18 4:50 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
Richard MacCutchan5-Apr-18 6:10
mveRichard MacCutchan5-Apr-18 6:10 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
enginestar5-Apr-18 6:57
enginestar5-Apr-18 6:57 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
Richard MacCutchan5-Apr-18 7:00
mveRichard MacCutchan5-Apr-18 7:00 
GeneralRe: Newbie: how do I analyse DOM Objects? Pin
Christian75739-Apr-18 15:51
Christian75739-Apr-18 15:51 
QuestionisAuthenticated() always returns false irrespective whether user is logged in or not Pin
Member 137573661-Apr-18 22:55
Member 137573661-Apr-18 22:55 
QuestionHow do i create an apps using android studio? Pin
Siti nasuha28-Mar-18 16:12
Siti nasuha28-Mar-18 16:12 
QuestionSetting a variable to a string..Do.. While loop Pin
esljustin26-Mar-18 14:15
esljustin26-Mar-18 14:15 
AnswerRe: Setting a variable to a string..Do.. While loop Pin
Richard MacCutchan26-Mar-18 22:15
mveRichard MacCutchan26-Mar-18 22:15 
AnswerRe: Setting a variable to a string..Do.. While loop Pin
Weavr8-Apr-18 0:39
Weavr8-Apr-18 0:39 
Questionany shortcut to toggle in and out the jquery code Pin
indian14323-Mar-18 8:43
indian14323-Mar-18 8:43 
QuestionText to Image Font Size Pin
Member 1374210822-Mar-18 17:51
Member 1374210822-Mar-18 17:51 
AnswerRe: Text to Image Font Size Pin
Richard Deeming23-Mar-18 2:46
mveRichard Deeming23-Mar-18 2:46 
QuestionHow to fetch unchecked checkbox value Pin
Member 1372997516-Mar-18 1:25
Member 1372997516-Mar-18 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.