Skip to content

Commit

Permalink
Merge pull request #34 from MichMich/pr/30
Browse files Browse the repository at this point in the history
Update for compliments.
  • Loading branch information
MichMich committed Nov 3, 2015
2 parents 067ef7e + e0de566 commit 9a5a74e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions js/compliments/compliments.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,30 @@ var compliments = {
*/
compliments.updateCompliment = function () {



var _list = [];

var hour = moment().hour();

// In the followign if statement we use .slice() on the
// compliments array to make a copy by value.
// This way the original array of compliments stays in tact.

if (hour >= 3 && hour < 12) {
// Morning compliments
_list = compliments.complimentList['morning'];
_list = compliments.complimentList['morning'].slice();
} else if (hour >= 12 && hour < 17) {
// Afternoon compliments
_list = compliments.complimentList['afternoon'];
_list = compliments.complimentList['afternoon'].slice();
} else if (hour >= 17 || hour < 3) {
// Evening compliments
_list = compliments.complimentList['evening'];
_list = compliments.complimentList['evening'].slice();
} else {
// Edge case in case something weird happens
// This will select a compliment from all times of day
Object.keys(compliments.complimentList).forEach(function (_curr) {

_list = _list.concat(compliments.complimentList[_curr]);

_list = _list.concat(compliments.complimentList[_curr]).slice();
});
}

Expand All @@ -44,12 +48,12 @@ compliments.updateCompliment = function () {

// If it exists, remove it so we don't see it again
if (_spliceIndex !== -1) {
_list = _list.slice(_spliceIndex, 1);
_list.splice(_spliceIndex, 1);
}

// Randomly select a location
var _location = Math.floor(Math.random() * _list.length);
compliments.currentCompliment = _list[_location];
var _randomIndex = Math.floor(Math.random() * _list.length);
compliments.currentCompliment = _list[_randomIndex];

$('.compliment').updateWithText(compliments.currentCompliment, compliments.fadeInterval);

Expand Down
2 changes: 1 addition & 1 deletion js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var config = {
}
},
compliments: {
interval: 2000,
interval: 30000,
fadeInterval: 4000,
morning: [
'Good morning, handsome!',
Expand Down

0 comments on commit 9a5a74e

Please sign in to comment.