var targetPosition;
startCurrentView();
$( "#draggable" ).draggable({ containment: "#containment-wrapper", scroll: false , 
	drag: function(){
            // var offset = $(this).offset();
            // var xPos = offset.left;
            // var yPos = offset.top;
            //console.log('x: ' + xPos);
            //console.log('y: ' + yPos);
    },
    stop: function(){
        // Bottom-left coordinates
        var finalPosition = $(this).position();
        // Getting position for the center of the image
        var finalxPos = finalPosition.left + $(this).width() / 2;
        var finalyPos = finalPosition.top + $(this).height() / 2; 
        var parentWidth = $("#containment-wrapper").width();
        var parentHeight = $("#containment-wrapper").height();
        console.log('Final X: ' + finalxPos);
        console.log('Final Y: ' + finalyPos);
        console.log('Parent size: ' + parentWidth + " x " + parentHeight);

        targetPosition = processPosition(finalxPos, finalyPos, parentWidth, parentHeight);
    }
});

$('.submit').click(submit);

function processPosition(xPos, yPos, parentWidth, parentHeight) {
    const horizRegions = 3;
    const vertRegions = 3;
    const positionNames = ["Back-left", "Back", "Back-Right", "Left", "Centre", "Right", "Front-Left", "Front", "Front-Right"];
    var column = Math.floor(xPos / (parentWidth / horizRegions));
    var row = Math.floor(yPos / (parentHeight / vertRegions));
    var positionIndex = row * horizRegions + column;
    var result = positionNames[positionIndex];
    return result;
}

function submit() {
    var username = getUsername();
    startLoadingAnimation("Answered " + answer.toLowerCase() + "!");
    database.ref('decision-where-david').update({
        [username]: targetPosition
    });
    console.log("David's target position: " + targetPosition);
    finishedCurrentView(1000);
}
@@ -115,18 +115,17 @@
  false ,
- 
 %0A
+
 %09drag: f
@@ -639,17 +639,16 @@
 t() / 2;
- 
 %0A       
@@ -763,32 +763,35 @@
 eight();%0A       
+ //
  console.log('Fi
@@ -812,32 +812,35 @@
 alxPos);%0A       
+ //
  console.log('Fi
@@ -869,16 +869,19 @@
 %0A       
+ //
  console
@@ -1588,24 +1588,67 @@
  submit() %7B%0A
+    if (targetPosition != undefined) %7B%0A    
     var user
@@ -1673,16 +1673,20 @@
 ();%0A    
+  
+  
 startLoa
@@ -1717,14 +1717,22 @@
 %22 + 
-answer
+targetPosition
 .toL
@@ -1750,16 +1750,20 @@
 + %22!%22);%0A
+    
     data
@@ -1812,16 +1812,20 @@
         
+    
 %5Busernam
@@ -1843,16 +1843,20 @@
 osition%0A
+    
     %7D);%0A
@@ -1855,24 +1855,28 @@
     %7D);%0A    
+   
+ 
 console.log(
@@ -1922,16 +1922,20 @@
 ition);%0A
+    
     fini
@@ -1957,9 +1957,15 @@
 (1000);%0A
+    %7D%0A
 %7D

hotfix answer undefined