Why is jQuery not adding numbers properly?
Here is my JavaScript code:
Is the logic contained in this code correct? I noticed that when the $RoundOneEarnings is increased by the correct amount only after the first question is answered. Afterwards, it increases it by the wrong amount.
var $RoundOneEarnings=0; //global variable for Round One earnings.
function showClue(e)
{
var eventTarget=e.target;
if (eventTarget.id=='10')
{
function inputProcessing (e)
{
var $end_time=e.timeStamp;
var $end_time_converted=$end_time/1000 |0;
var $elapsed_time=($end_time_converted-$start_time)*(-1)*(1/10) |0;
if ($elapsed_time<=1)
{
$('#top-result').text('Elapsed time: '+$elapsed_time+' second;');
}
else
{
$('#top-result').text('Elapsed time: '+$elapsed_time+' seconds;');
}
var $correct_answer_1='PRESIDENT JAMES MADISON'
, $correct_answer_2='JAMES MADISON'
, $correct_answer_3='MADISON';
if (($('input').val()==$correct_answer_1 || $correct_answer_2 || $correct_answer_3) && $elapsed_time<=5)
{
$('#top-result').append('<span id="prize"> CORRECT AND WITHIN TIME LIMIT! +$200!</span>');
$RoundOneEarnings += 200;
}
if (($('input').val()==$correct_answer_1 || $correct_answer_2 || $correct_answer_3) && $elapsed_time>5)
{
$('#top-result').append('<span id="no-prize"> CORRECT BUT EXCEEDED TIME LIMIT! -$200!</span>');
$RoundOneEarnings -= 200;
}
if (($('input').val()==!$correct_answer_1 || !$correct_answer_2 || !$correct_answer_3) && $elapsed_time<=5)
{
$('#top-result').append('<span id="no-prize"> INCORRECT! -$200!</span>');
$RoundOneEarnings -= 200;
}
if (($('input').val()==!$correct_answer_1 || !$correct_answer_2 || !$correct_answer_3) && $elapsed_time>5)
{
$('#top-result').append('<span id="no-prize"> INCORRECT! -$200!</span>');
$RoundOneEarnings -= 200;
}
$('#top-current-prize-earnings').text('Your current prize earnings are now: $'+ $RoundOneEarnings);
};
$(this).attr("id","clue_whichPresident").text("\"FATHER\" OF THE U.S. CONSTITUTION");
$('#top-response-container').html('<form>RESPONSE: '+'<input type="text"></input>'+'</form>');
$('input').focus();
var $start_time=new Date().getSeconds();
$('#top-response-container').on("blur","input",inputProcessing);
if (eventTarget.id=='20')
{
function inputProcessing(e)
{
var $end_time=e.timeStamp;
var $end_time_converted=$end_time/1000 |0;
var $elapsed_time=($end_time_converted-$start_time)*(-1)*(1/10) |0;
if ($elapsed_time<=1)
{
$('#top-result').text('Elapsed time: '+$elapsed_time+' second;');
}
else
{
$('#top-result').text('Elapsed time: '+$elapsed_time+' seconds;');
}
var $correct_answer_1='PRESIDENT JOHN ADAMS'
, $correct_answer_2='PRESIDENT ADAMS'
, $correct_answer_3='JOHN ADAMS';
if (($('input').val()==$correct_answer_1 || $correct_answer_2 || $correct_answer_3) && $elapsed_time<=5)
{
$('#top-result').append('<span id="prize"> CORRECT AND WITHIN TIME LIMIT! +$400!</span>');
$RoundOneEarnings += 400;
}
if (($('input').val()==$correct_answer_1 || $correct_answer_2 || $correct_answer_3) && $elapsed_time>5)
{
$('#top-result').append('<span id="no-prize"> CORRECT BUT EXCEEDED TIME LIMIT! -$400!</span>');
$RoundOneEarnings -= 400;
}
if (($('input').val()==!$correct_answer_1 || !$correct_answer_2 || !$correct_answer_3) && $elapsed_time<=5)
{
$('#top-result').append('<span id="no-prize"> INCORRECT! -$400!</span>');
$RoundOneEarnings -= 400;
}
if (($('input').val()==!$correct_answer_1 || !$correct_answer_2 || !$correct_answer_3) && $elapsed_time>5)
{
$('#top-result').append('<span id="no-prize"> INCORRECT! -$400!</span>');
$RoundOneEarnings -= 400;
}
$('#top-current-prize-earnings').text('Your current prize earnings are now: $'+ $RoundOneEarnings);
};
$(this).attr("id","clue_whichPresident").text("MIDNIGHT APPOINTMENTS");
$('#top-response-container').html('<form>RESPONSE: '+'<input type="text"></input>'+'</form>');
$('input').focus();
var $start_time=new Date().getSeconds();
$('#top-response-container').on("blur","input",inputProcessing);
}
}