Here is some simple code that takes the id values of “.somedivs” and puts them into global variables to be sorted by the conditional statements, then to the console. Below you can see that I am getting some weird results and no matter what combination of conditionals I use I can’t get it to work right. Seems so basic, I’m thinking I’m violating some law of js or i’m missing something obvious.
$(document).ready(function(){
$('.somedivs').mousedown(function(){
first = $(this).attr("id");
}).mouseup(function(){
second = $(this).attr("id");
if(window.first > window.second){
var higher = window.first;
var lower = window.second;
var process = 1;
}else if(window.second > window.first){
var higher = window.second;
var lower = window.first;
var process = 2;
}else if(window.first === window.second){
var higher = window.first;
var lower = window.second;
var process = 3;
}
if(higher > lower){
var status = true;
}else{
var status = false;
}
console.log("process = " + process + " // " + "window.first = "+window.first+" / window.second = "+window.second + " // higher = "+higher+" / lower = "+lower + " // status = "+ status );
});
Console output, as you can see most of the lines are returning true when they should be false, if you look at the numbers themselves. I marked some of the ones that are wrong with the arrow “>”. Why is status true when it should be false?
process = 2 // window.first = 0 / window.second = 1 // higher = 1 / lower = 0 // status = true
process = 3 // window.first = 2 / window.second = 2 // higher = 2 / lower = 2 // status = false
process = 1 // window.first = 2 / window.second = 0 // higher = 2 / lower = 0 // status = true
> process = 1 // window.first = 5 / window.second = 22 // higher = 5 / lower = 22 // status = true
process = 3 // window.first = 7 / window.second = 7 // higher = 7 / lower = 7 // status = false
process = 2 // window.first = 3 / window.second = 9 // higher = 9 / lower = 3 // status = true
process = 1 // window.first = 19 / window.second = 14 // higher = 19 / lower = 14 // status = true
> process = 1 // window.first = 5 / window.second = 11 // higher = 5 / lower = 11 // status = true
process = 1 // window.first = 35 / window.second = 23 // higher = 35 / lower = 23 // status = true
process = 2 // window.first = 13 / window.second = 17 // higher = 17 / lower = 13 // status = true
process = 1 // window.first = 32 / window.second = 24 // higher = 32 / lower = 24 // status = true
process = 2 // window.first = 17 / window.second = 18 // higher = 18 / lower = 17 // status = true
process = 1 // window.first = 22 / window.second = 18 // higher = 22 / lower = 18 // status = true
> process = 1 // window.first = 8 / window.second = 11 // higher = 8 / lower = 11 // status = true
process = 1 // window.first = 18 / window.second = 14 // higher = 18 / lower = 14 // status = true
process = 2 // window.first = 3 / window.second = 6 // higher = 6 / lower = 3 // status = true
process = 1 // window.first = 24 / window.second = 16 // higher = 24 / lower = 16 // status = true
process = 1 // window.first = 9 / window.second = 15 // higher = 9 / lower = 15 // status = true
process = 1 // window.first = 31 / window.second = 26 // higher = 31 / lower = 26 // status = true
process = 2 // window.first = 24 / window.second = 28 // higher = 28 / lower = 24 // status = true
process = 1 // window.first = 41 / window.second = 30 // higher = 41 / lower = 30 // status = true
process = 2 // window.first = 13 / window.second = 19 // higher = 19 / lower = 13 // status = true
I thinik it is because of the type of the variable:
try :
and