This question piggy backs off of a question I asked yesterday. That question was:
"if" statement parameters not functioning as intended. JavaScript
But now i'm Getting a NaN error when I implement the following code:
var targetBoxLeft = parseFloat(document.getElementById("targetBox").style.left);
bulletOne.style.left = bulletOneLeft;
if (bulletOneLeft > targetBoxLeft){
document.getElementById("targetBox").style.opacity = "0";
};
Yesterday I didn't use "parseFloat", however my question is, if i'm specifically describing the parameter of targetBoxLeft as a CSS style.left property; why wouldn't that be a specific number? and why wouldn't it take on the number of left: 310px; as specified by the elements properties itself?
#targetBox{
position: absolute;
background-color: green;
height: 20px;
width: 20px;
top: 30px;
left: 310px;
opacity: 1;
}
Logically should the following 2 lines of code detect ACTUAL numbers?;
var bulletOneLeft = bulletOne.style.left;
var targetBoxLeft = targetBox.style.left;
And then once the above variables are detected as actual numbers, should the following if statement code be able to compare them depending on their values at any given time if movement(bulletOneLeft++;) is involved?:
if (bulletOneLeft > targetBoxLeft){
document.getElementById("targetBox").style.opacity = "0";
};
Im not exactly sure whats happening but since i'm getting a NaN error for when targetBox.style.left is read by the code i'm guessing that maybe a CSS property needs additional code to be converted into an actual number/variable before I run the if statement with corresponding VAR's?