Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2013
    Posts
    23
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Matching different images

    hi, i am trying to match images. this one works fine only with same images but i want to match unidentical images based on their id or src

    below is the working code for similar images

    http://jsfiddle.net/GquLr/

    can u help me the code with different images based on the image id or src. i am trying to do but i cant get it. plz help me with...


    regards
    kadi

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Is this supposed to be a "matching" game? Where the player reveals two images and, if they match, then they win?

    If so, I wouldn't even begin to code it like that. I'd put just the 3 image URLs into an array and then use code to create an array of double that size with each URL in there twice, shuffle the array, and then "deal" the cards face down. That code, where you have to put each image in place on the screen twice ahead of time is clumsy. Plus, if you wanted to change the number of images to 4 or 5 or 10 you'd have to almost rewrite the page.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    And when you say "unidentical", how could you then expect to match on .src when that value will be different for each image?? Matching on ID is possible, except that IDs are supposed to be UNIQUE on a page. So matching on name would be better (names don't have to be unique).
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,618
    Thanks
    0
    Thanked 645 Times in 635 Posts
    See http://www.felgall.com/jstip173.htm for a matching game that allows for one or two sets of images. Where a second set of images is provided the images match those in the same position in the extra array.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •