Hello guys!
I have been trying to create a if/else statement code in jQuery but I guess my if/else statement is resting in peace! I don’t know what is getting wrong I have did everything and still it is not working correctly! Ok, here is my problem list ~
- My
if/elseis getting inverse! - And I think everything is just getting messed up!
- JsLint (in jsFiddle.net) is showing no error in my jQuery code!
Please here is my problem demo link ~~~~~~~~~~
Here is my smaple jQuery code ~~~~~~~~~
$(function () {
var correct = '10';
var incorrect = '9';
$('div.correct_incorrect').css("background",function () {
if( correct > incorrect )
{
return "#796";
}
else if( correct == incorrect )
{
return "#345";
}
else
{
return "#732";
}
});
});
Please help me out!
THANKS IN ADVANCE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sorry to bother guys but my previous question is solved but I’m having a new problem with this code. Here I’m trying to retrive a value from two input elements! But it is not working.
Please have a look here —-
THANKS IN ADVANCE (for this one too!)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The problem is that
correctandincorrectare strings. You can change them to integers to fix your problem:Alternatively, you can use
parseInt(myNumAsString, 10)to convert a string to a number at runtime.