30
rated 0 times
[
37]
[
7]
/ answers: 1 / hits: 22879
/ 12 Years ago, tue, august 28, 2012, 12:00:00
I am using a jQuery Based Memory Game on my site. It works well overall but I want a Play Again Link and stats at the end to show. I cannot get that code to work. I see this error:
TypeError: $ is not a function
[Break On This Error]
var game = $('div.slashc-memory-game'); // get the game
Here is the JS:
// this script shows how you can get info about the game
var game = $('div.slashc-memory-game'); // get the game
var info = $('p#info').find('span'); // get the info box
var playAgain = $('a#play-again').css('visibility', 'hidden'); // get the play again link
// format time like hh:mm:ss
var formatTime = function(s)
{
var h = parseInt(s / 3600), m = parseInt((s - h * 3600) / 60); s = s % 60;
return (h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s);
}
// listen for game 'done' event
game.bind('done', function(e)
{
// show basic stats
var stats = game.slashcMemoryGame('getStats');
info.html('Success ! Number of clicks : ' + stats.numClicks + ', elapsed time : ' + formatTime(parseInt(stats.time / 1000)) + '.');
playAgain.css('visibility', 'visible'); // show link
});
// play again action
playAgain.click(function(e)
{
playAgain.css('visibility', 'hidden'); // hide link
info.html('Memory Game, click to reveal images'); // reset text
game.slashcMemoryGame('restart'); // restart game
e.preventDefault();
});
Here is a Fiddle
More From » jquery