jquery - Javascript higher & lower variable conditionals odd console output -



jquery - Javascript higher & lower variable conditionals odd console output -

here simple code takes id values of ".somedivs" , puts them global variables sorted conditional statements, console. below can see getting weird results , no matter combination of conditionals utilize can't work right. seems basic, i'm thinking i'm violating law of js or i'm missing obvious.

$(document).ready(function(){ $('.somedivs').mousedown(function(){ first = $(this).attr("id"); }).mouseup(function(){ sec = $(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, can see of lines returning true when should false, if @ numbers themselves. marked of ones wrong arrow ">". why status true when should 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 because of type of variable:

try :

first = parseint($(this).attr("id"));

and

second = parseint($(this).attr("id"));

javascript jquery

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -