Uncaught ReferenceError: picturePath is not defined

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

  1. <!DOCTYPE html> 
  2. <html>
  3. <head>
  4. <!-- This is a comment tag -->
  5. <meta charset="UTF-8" />
  6. <title></title>
  7. <link rel="stylesheet" href="generic.css" type="text/css" media="screen,projection" />
  8. <script type="text/javascript" src="jquery-2.1.3.min.js"></script>
  9. <script type="text/javascript">
  10. // Global variables go here
  11. var picture = new Image();
  12. // functions go below here
  13. function startPicturePuzzle(picturePath)
  14. {
  15. // Set picturePuzzle division to relative
  16. $('#picturePuzzle').css('position', 'relative');

  17. // Load the picture
  18. $(picture)
  19. .load(function() {
  20. getPicturePuzzleDifficulty();
  21. })
  22. // if there is a loading error
  23. .error(function () {
  24. // notify the user
  25. $('#picturePuzzle')
  26. .html("<h1>Picture Puzzle<br />Unable to load image</h1>")
  27. .find("h1").each(function() {
  28. $(this).css('position', 'absolute');
  29. $(this).css('left', Math.floor(($('#picturePuzzle').width() - $(this).width())/2) + "px");
  30. $(this).css('top', Math.floor(($('#picturePuzzle').height() - $(this).height())/2) + "px");
  31. });
  32. })
  33. // Set the src attribute to load the image
  34. .attr('src', picturePath);
  35. }
  36. function getPicturePuzzleDifficulty()
  37. {
  38. $('#picturePuzzle')
  39. .css('background-image', 'url("' + $(picture).attr('src') + '")')
  40. .css('background-position', 'center center')
  41. .css('background-repeat', 'no-repeat')
  42. .css('background-size', 'contain')
  43. .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>");

  44. $('#picturePuzzle > h2')
  45. .css('padding', '2px 5px')
  46. .css('background-color', 'lightgrey');
  47. $('#picturePuzzle h2:nth-child(3)')
  48. .css('position', 'relative')
  49. .css('top', ($('#picturePuzzle').height() - ($('#picturePuzzle h2:nth-child(3)').height() * 2) - 8) + "px")
  50. .find('span:nth-child(2)')
  51. .css('padding-left', '80px');
  52. $('#dialog p')
  53. .css('background-color', 'black')
  54. .css('color', 'white')
  55. .css('padding', '2px 5px');
  56. $('#dialog h2')
  57. .css('padding', '5px');
  58. $('#dialog button')
  59. .css('padding', '2px 5px')
  60. .css('float', 'right')
  61. .css('color', 'white')
  62. .css('background-color', 'IndianRed');
  63. $('#dialog')
  64. .css('background-color', 'white')
  65. .css('opacity', '0.8')
  66. .css('position', 'absolute')
  67. .css('top', Math.floor(($('#picturePuzzle').height() - $('#dialog').height())/2) +"px")
  68. .css('left', Math.floor(($('#picturePuzzle').width() - $('#dialog').width())/2) +"px");
  69. $('#difficult').on('click', function() {
  70. $('#dialog').remove();
  71. $('#picturePuzzle').css('background-image', 'none');
  72. setupPicturePuzzle(picturePath, 5);
  73. });
  74. $('#medium').on('click', function() {
  75. $('#dialog').remove();
  76. $('#picturePuzzle').css('background-image', 'none');
  77. setupPicturePuzzle(picturePath, 4);
  78. });
  79. $('#easy').on('click', function() {
  80. $('#dialog').remove();
  81. $('#picturePuzzle').css('background-image', 'none');
  82. setupPicturePuzzle(picturePath, 3);
  83. });
  84. }
  85. function setupPicturePuzzle(difficulty)
  86. {
  87. var gridY, gridX, gridID = 1;
  88. var picWidth, picHeight, ratio;
  89. // create picture grid element
  90. $('#picturePuzzle > h2:nth-child(1)')
  91. .after("<div id='grid'></div>");
  92. // work out the renderable width and height of the picture
  93. if (picture.naturalWidth > picture.naturalHeight)
  94. {
  95. picWidth = $('#picturePuzzle').innerWidth();
  96. ratio = picture.naturalWidth / picWidth;
  97. picHeight = Math.floor(picture.naturalHeight / ratio) - 8;
  98. $('#grid')
  99. .css('position', 'relative')
  100. .css('top', ((($('#picturePuzzle').height() - picHeight) /2) - $('#picturePuzzle > h2:nth-child(1)').height()));
  101. }
  102. else
  103. {
  104. picHeight = ($('#picturePuzzle').height() - ($('#picturePuzzle > h2:nth-child(1)').height() * 2)) - 8;
  105. ratio = picture.naturalHeight / picHeight;
  106. picWidth = Math.floor(picture.naturalWidth / ratio);
  107. $('#grid')
  108. .css('position', 'relative')
  109. .css('left', ($('#picturePuzzle').width() - picWidth) + "px");
  110. }
  111. // work out the tile width and height
  112. segWidth = (Math.floor(picWidth / difficulty) - 2);
  113. segHeight = (Math.floor(picHeight / difficulty) - 2);
  114. for (gridY=0; gridY<difficulty; gridY++)
  115. {
  116. for (gridX=0; gridX<difficulty; gridX++)
  117. {
  118. if (!((gridY == (difficulty - 1)) && (gridX == (difficulty - 1))))
  119. {
  120. // setup grid value
  121. gameGrid[gridY][gridX] = gridID;
  122. // add grid element and style its background
  123. $('#grid').append("<a href='#' id='grid" + gridID + "'><div></div></a>");
  124. $('#grid' + gridID + ' > div')
  125. .css('width', segWidth + "px")
  126. .css('height', segHeight + "px")
  127. .css('background-image', 'url("' + $(picture).attr('src') + '")')
  128. .css('background-size', picWidth + 'px ' + picHeight + 'px')
  129. .css('background-position', '-' + (gridX *segWidth) + 'px -' +(gridY * segHeight) + 'px');
  130. $('#grid' + gridID)
  131. .css('border', '1px solid green')
  132. .css('position', 'absolute')
  133. .css('top', (gridY *(segHeight + 2)) + "px")
  134. .css('left', (gridX * (segWidth + 2)) + "px");
  135. gridID++;
  136. }
  137. else
  138. {
  139. gameGrid[gridY][gridX] = 0;
  140. }
  141. }
  142. }
  143. $( document ).ready(function() {
  144. // initial function call goes here
  145. startPicturePuzzle("Birkenhead Park.jpg");
  146. });

  147. </script>
  148. </head>
  149. <body>
  150. <!-- HTML goes here -->
  151. <div id="picturePuzzle">
  152. </body>
  153. </html>