I wrote a script that, upon button click, finds the closest location to your current position by searching through an array. It then locates the corresponding entry in another array and adds a number to that entry. However, I encountered a problem with appending the value. Instead of starting with "0" and adding 1 to make it "1", it displays as "01". I initially thought this was due to it being treated as a string, so I attempted parsing it as an integer which didn't resolve the issue. It seems like there might be an issue with how I set the values in the array initially. I looped through the first 200 values and set them to 0, but I want this operation to run only once. Then, each time the button is clicked, it should append the inputted number to a text field. I'm uncertain about the next steps to take to address this concern. Here's the code section:
I've tried to pinpoint the critical sections of my code where I suspect the problem exists.
Here's a screenshot showing the issue (the entered value gets attached at the end instead of getting added):
jQuery(function($){
var Loc1;
var Loc2;
var service;
var marker = [];
var pos;
var infowindow;
var placeLoc
**var j;**
**var markerValue = [];**
**for (j = 0; j<200; j++ ){
markerValue[j] = 0;
}**
var markers;
var x = 0, y = 0,
vx = 0, vy = 0,
ax = 0, ay = 0;
var points;
var sphere = document.getElementById("sphere");
var counting = false;
var counter = 0;
var numberOne;
if (window.DeviceMotionEvent != undefined) {
window.ondevicemotion = function(e) {
ax = event.accelerationIncludingGravity.x * 5;
ay = event.accelerationIncludingGravity.y * 5;
document.getElementById("counterSpan").innerHTML = Math.round(counter*10)/10;
//document.getElementById("accelerationX").innerHTML = Math.round(e.accelerationIncludingGravity.x * 10)/10;
//document.getElementById("accelerationY").innerHTML = Math.round(e.accelerationIncludingGravity.y * 10)/10;
//document.getElementById("accelerationZ").innerHTML = Math.round(e.accelerationIncludingGravity.z * 10)/10;
var moveX = Math.round(e.accelerationIncludingGravity.x * 10)/10;
//var moveY = Math.round(e.accelerationIncludingGravity.y * 10)/10;
//var moveZ = Math.round(e.accelerationIncludingGravity.z * 10)/10;
if(moveX > 5 || moveX < -5) {
counting = true;
//alert(counting);
if(counter < 100){counter+=0.01;}
}
... // Truncated for brevity
});**
});// JavaScript Document