Uncaught ReferenceError: picturePath is not defined
apparently i haven't defined the function picturePath, but i'm not sure where or how to. errors occur on 86, 92, 98
- <!DOCTYPE html>
- <html>
- <head>
- <!-- This is a comment tag -->
- <meta charset="UTF-8" />
- <title></title>
- <link rel="stylesheet" href="generic.css" type="text/css" media="screen,projection" />
- <script type="text/javascript" src="jquery-2.1.3.min.js"></script>
- <script type="text/javascript">
-
- // Global variables go here
- var picture = new Image();
-
-
- // functions go below here
- function startPicturePuzzle(picturePath)
- {
- // Set picturePuzzle division to relative
- $('#picturePuzzle').css('position', 'relative');
-
- // Load the picture
- $(picture)
- .load(function() {
- getPicturePuzzleDifficulty();
- })
- // if there is a loading error
- .error(function () {
- // notify the user
- $('#picturePuzzle')
- .html("<h1>Picture Puzzle<br />Unable to load image</h1>")
- .find("h1").each(function() {
- $(this).css('position', 'absolute');
- $(this).css('left', Math.floor(($('#picturePuzzle').width() - $(this).width())/2) + "px");
- $(this).css('top', Math.floor(($('#picturePuzzle').height() - $(this).height())/2) + "px");
- });
-
- })
- // Set the src attribute to load the image
- .attr('src', picturePath);
- }
-
- function getPicturePuzzleDifficulty()
- {
- $('#picturePuzzle')
- .css('background-image', 'url("' + $(picture).attr('src') + '")')
- .css('background-position', 'center center')
- .css('background-repeat', 'no-repeat')
- .css('background-size', 'contain')
- .html("<h2>Picture Puzzle</h2><div id='dialog'>" + "<p>Difficulty</p><h2>Please choose a difficulty</h2>"+ "<button id='difficult'>Difficult</button>" + "<button id='medium'>Medium</button>" + "<button id='easy'>Easy</button></div>" + "<h2><span id='time'>Time: </span>" + "<span id='moves'>Moves: </span></h2>");
-
- $('#picturePuzzle > h2')
- .css('padding', '2px 5px')
- .css('background-color', 'lightgrey');
-
- $('#picturePuzzle h2:nth-child(3)')
- .css('position', 'relative')
- .css('top', ($('#picturePuzzle').height() - ($('#picturePuzzle h2:nth-child(3)').height() * 2) - 8) + "px")
- .find('span:nth-child(2)')
- .css('padding-left', '80px');
-
- $('#dialog p')
- .css('background-color', 'black')
- .css('color', 'white')
- .css('padding', '2px 5px');
-
- $('#dialog h2')
- .css('padding', '5px');
-
- $('#dialog button')
- .css('padding', '2px 5px')
- .css('float', 'right')
- .css('color', 'white')
- .css('background-color', 'IndianRed');
-
- $('#dialog')
- .css('background-color', 'white')
- .css('opacity', '0.8')
- .css('position', 'absolute')
- .css('top', Math.floor(($('#picturePuzzle').height() - $('#dialog').height())/2) +"px")
- .css('left', Math.floor(($('#picturePuzzle').width() - $('#dialog').width())/2) +"px");
-
- $('#difficult').on('click', function() {
- $('#dialog').remove();
- $('#picturePuzzle').css('background-image', 'none');
- setupPicturePuzzle(picturePath, 5);
- });
-
- $('#medium').on('click', function() {
- $('#dialog').remove();
- $('#picturePuzzle').css('background-image', 'none');
- setupPicturePuzzle(picturePath, 4);
- });
-
- $('#easy').on('click', function() {
- $('#dialog').remove();
- $('#picturePuzzle').css('background-image', 'none');
- setupPicturePuzzle(picturePath, 3);
- });
-
- }
-
- function setupPicturePuzzle(difficulty)
- {
- var gridY, gridX, gridID = 1;
- var picWidth, picHeight, ratio;
-
- // create picture grid element
- $('#picturePuzzle > h2:nth-child(1)')
- .after("<div id='grid'></div>");
-
- // work out the renderable width and height of the picture
- if (picture.naturalWidth > picture.naturalHeight)
- {
- picWidth = $('#picturePuzzle').innerWidth();
- ratio = picture.naturalWidth / picWidth;
- picHeight = Math.floor(picture.naturalHeight / ratio) - 8;
- $('#grid')
- .css('position', 'relative')
- .css('top', ((($('#picturePuzzle').height() - picHeight) /2) - $('#picturePuzzle > h2:nth-child(1)').height()));
- }
- else
- {
- picHeight = ($('#picturePuzzle').height() - ($('#picturePuzzle > h2:nth-child(1)').height() * 2)) - 8;
- ratio = picture.naturalHeight / picHeight;
- picWidth = Math.floor(picture.naturalWidth / ratio);
- $('#grid')
- .css('position', 'relative')
- .css('left', ($('#picturePuzzle').width() - picWidth) + "px");
- }
-
- // work out the tile width and height
- segWidth = (Math.floor(picWidth / difficulty) - 2);
- segHeight = (Math.floor(picHeight / difficulty) - 2);
-
- for (gridY=0; gridY<difficulty; gridY++)
- {
- for (gridX=0; gridX<difficulty; gridX++)
- {
- if (!((gridY == (difficulty - 1)) && (gridX == (difficulty - 1))))
- {
- // setup grid value
- gameGrid[gridY][gridX] = gridID;
-
- // add grid element and style its background
- $('#grid').append("<a href='#' id='grid" + gridID + "'><div></div></a>");
- $('#grid' + gridID + ' > div')
- .css('width', segWidth + "px")
- .css('height', segHeight + "px")
- .css('background-image', 'url("' + $(picture).attr('src') + '")')
- .css('background-size', picWidth + 'px ' + picHeight + 'px')
- .css('background-position', '-' + (gridX *segWidth) + 'px -' +(gridY * segHeight) + 'px');
-
- $('#grid' + gridID)
- .css('border', '1px solid green')
- .css('position', 'absolute')
- .css('top', (gridY *(segHeight + 2)) + "px")
- .css('left', (gridX * (segWidth + 2)) + "px");
-
- gridID++;
- }
- else
-
- {
- gameGrid[gridY][gridX] = 0;
- }
- }
- }
-
- }
-
- $( document ).ready(function() {
- // initial function call goes here
- startPicturePuzzle("Birkenhead Park.jpg");
- });
-
- </script>
- </head>
- <body>
- <!-- HTML goes here -->
- <div id="picturePuzzle">
- </body>
- </html>