From 2b3b655b36b4dfce90799c1685ebce8a8f78c2de Mon Sep 17 00:00:00 2001 From: Ryan Koven Date: Mon, 27 Jan 2014 18:57:30 -0500 Subject: [PATCH] Modified check_answer to update 'number to win' on progress bar on puzzle template --- assets/js/snacMan.js | 11 +++++++---- static/js/snacMan.js | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/assets/js/snacMan.js b/assets/js/snacMan.js index c63e34f..c56da5e 100644 --- a/assets/js/snacMan.js +++ b/assets/js/snacMan.js @@ -9,6 +9,7 @@ $(function(){ var wrong_answers = $('#wrong_answers').val().split(' '); ///////////////// + var munched_correct = 0; var num_correct = right_answers.length; var corrects = {}; for (var i = 0; i < num_correct; i++){ @@ -25,11 +26,13 @@ $(function(){ }); // Check if answer in the column is a key in the corrects object; - // change progress bar if it is. + // if it is, change progress bar and update num_to_win div. var check_answer = function(cell){ if ($('#answer' + cell).html() in corrects){ + munched_correct++; var height = parseInt($('#progress_bar').css('height')); - $('#progress_bar').css('height', (height + 20) + "px") + $('#progress_bar').css('height', (height + 20) + "px"); + $('#num_to_win').html((num_correct - munched_correct) + " to Win"); } }; @@ -39,8 +42,8 @@ $(function(){ var chew_timeout = function(i, j){ setTimeout(function(){ - $('#' + cell).attr('src', 'http://www.googlefacebooktwitter.com/img/eat/eat' + i +'.png'); - margin_top += ((j < 5) ? -40 : 40) + $('#' + cell).attr('src', 'http://www.googlefacebooktwitter.com/img/eat/eat' + i + '.png'); + margin_top += ((j < 5) ? -40 : 40); $('.muncher').css('margin-top', margin_top + "px"); }, j*20); } diff --git a/static/js/snacMan.js b/static/js/snacMan.js index c63e34f..c56da5e 100644 --- a/static/js/snacMan.js +++ b/static/js/snacMan.js @@ -9,6 +9,7 @@ $(function(){ var wrong_answers = $('#wrong_answers').val().split(' '); ///////////////// + var munched_correct = 0; var num_correct = right_answers.length; var corrects = {}; for (var i = 0; i < num_correct; i++){ @@ -25,11 +26,13 @@ $(function(){ }); // Check if answer in the column is a key in the corrects object; - // change progress bar if it is. + // if it is, change progress bar and update num_to_win div. var check_answer = function(cell){ if ($('#answer' + cell).html() in corrects){ + munched_correct++; var height = parseInt($('#progress_bar').css('height')); - $('#progress_bar').css('height', (height + 20) + "px") + $('#progress_bar').css('height', (height + 20) + "px"); + $('#num_to_win').html((num_correct - munched_correct) + " to Win"); } }; @@ -39,8 +42,8 @@ $(function(){ var chew_timeout = function(i, j){ setTimeout(function(){ - $('#' + cell).attr('src', 'http://www.googlefacebooktwitter.com/img/eat/eat' + i +'.png'); - margin_top += ((j < 5) ? -40 : 40) + $('#' + cell).attr('src', 'http://www.googlefacebooktwitter.com/img/eat/eat' + i + '.png'); + margin_top += ((j < 5) ? -40 : 40); $('.muncher').css('margin-top', margin_top + "px"); }, j*20); }