SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need with a small javascript

    can anyone tell me what is wrong with this small javascript that I wrote for managing the concentration game?

    <html>
    <head>
    <!--

    Filename: tiles.htm
    Supporting files: ldown.gif, lup.gif, pback.jpg, pr.gif, premier.css,
    rdown.gif, rup.gif, slide00.jpg - slide11.jpg

    -->

    <title>The Concentration Game</title>
    <link href="games.css" rel="stylesheet" type="text/css" />
    <script src="tiles.js" type="text/javascript"></script>
    <script>

    var FlipCount, Tile1, Tile2;
    FlipCount=0

    //function ShowAll() {
    //for(i=0; i<=15; i++) {
    //document.write

    //}
    //}

    function FlipBack() {
    document.images[Tile1].src = "tile.jpg";
    document.images.[Tile2].src = "tile.jpg";
    FlipCount=0;
    }

    function CheckTiles() {
    if (document.images[Tile1].src == document.images[Tile2].src) {
    FlipCount=0;
    }
    else {
    setTimeout("FlipBack()", 8);
    }
    }

    function Flip(i) {
    document.images.[i].src = Tiles[i].src;
    if (FlipCount==0) {
    Tile1=i;
    FlipCount=1;
    }
    else {
    Tile2=i;
    CheckTiles();
    }
    }


    </script>
    </head>

    <body>
    <form action="">
    <!-- Concentration Tiles -->

    <div id="board">
    <a href="http://www.yahoo.com"><img src="tile.jpg" alt="" onClick="document.Flip(0)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(1)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(2)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(3)" width="75" height="75" /></a>
    <br />
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(4)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(5)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(6)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(7)" width="75" height="75" /></a>
    <br />
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(8)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(9)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(10)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(11)" width="75" height="75" /></a>
    <br />
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(12)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(13)" width="75" height="75"/></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(14)" width="75" height="75" /></a>
    <a href="#"><img src="tile.jpg" alt="" onmousedown="Flip(15)" width="75" height="75" /></a>
    </div>

    <div id="main">
    <p id="title">
    <img src="logo.jpg" alt="Game Etc." width="240" height="55" />
    </p>
    <p>Play the Concentration game! Click the tiles on the left and
    match pairs of identical images. Click the <b>Reload Tiles</b> button
    below to randomize the position of the tiles and play again. Click the
    <b>Show Tiles</b> button to view the solution.</p>
    <p id="formp">
    <input type="button" value="Reload Tiles" />&nbsp;&nbsp;
    <input type="button" value="Show Tiles" />
    </p>
    </div>

    </form>
    </body>
    </html>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,255
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    code

    Hi matecno, welcome to the forums,
    It would help if you put your code inside the appropriate BBcode tags (the "<>" icon in this case) as it's text highlighting helps reveal syntax errors.
    Please be a bit more specific, What is the script doing or not doing that you are having a problem with? Any error messages?

  3. #3
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error

    it just gives me error on page, I am sure it is something that has to do with the href attribute at the buttom of the page, can you help?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,255
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    errors

    I copied the code and opened the page in Firefox. The javascript error console shows this
    Error: missing name after . operator
    Source File: file:///C:/My%20Documents/matecno.html
    Line: 28, Column: 22
    Source Code:
    document.images.[Tile2].src = "tile.jpg";
    See the difference between that line and the one before it?
    HTML Code:
    document.images[Tile1].src = "tile.jpg";
    document.images.[Tile2].src = "tile.jpg";

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you check for syntax errors?


Bookmarks

Posting Permissions

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