Post by Thesealion on Apr 15, 2014 10:51:42 GMT -8
I am working on a Like Rank System where user's ranks will be based off of their likes. I am having a little trouble going through setting the ranks though. I will post the code below and then describe my problem:
Basically, I have an auto form where the user will input "like Rank name" and "required like count." Now I am trying to tell the code how to tell which rank to set.
The first part:
Is supposed to trigger when the rank is the first in the sequence and the number of likes is less than the next rank on the list.
The second part:
Is supposed to trigger when the rank is the last on the list and the number of likes is more than the amount required for that rank.
The third part:
Is supposed to trigger when the number of likes is more than or equal to the amount required to get that rank and less than the amount required for the next rank.
My problem is that only the first part seems to be working. The first rank starts at 0 and works fine, but once a user gets one like (which I have set to be the second rank right now...) the system throws an error: ""An error occurred during a document.ready call: " "TypeError: pb.plugin.get(...).settings.ranks[(i + 1)] is undefined" ""
I am afraid this is some sort of simple error, but I am currently not able to see it nor is my brother (he didn't have much time to look however...) does anyone know where I have gone wrong? Thanks for the help and your time!
$(document).ready(function(){
$(".mini-profile").each(function(){
var lik = $(this).find(".bob").text(); //.bob is a span I am putting around the like number in the template
var lnk = $(this).find(".user-link");
var ranks = pb.plugin.get('like_rank_system').settings.ranks;
for (var i=0;i<ranks.length;i++) {
if(i==0) {
if(lik < ranks[i+1].required_like_count) {
$(lnk).after('<br />'+ranks[i].rank);
}
}
else if(i == ranks.length && lik >= ranks[i].required_like_count) {
$(lnk).after('<br />'+ranks[i].rank);
}
else if(lik >= ranks[i].required_like_count && lik < ranks[i+1].required_like_count && i != ranks.length) {
$(lnk).after('<br />'+ranks[i].rank);
}
}
});
});
Basically, I have an auto form where the user will input "like Rank name" and "required like count." Now I am trying to tell the code how to tell which rank to set.
The first part:
if(i==0) {
if(lik < ranks[i+1].required_like_count) {
$(lnk).after('<br />'+ranks[i].rank);
}
}
Is supposed to trigger when the rank is the first in the sequence and the number of likes is less than the next rank on the list.
The second part:
else if(i == ranks.length && lik >= ranks[i].required_like_count) {
$(lnk).after('<br />'+ranks[i].rank);
}
Is supposed to trigger when the rank is the last on the list and the number of likes is more than the amount required for that rank.
The third part:
else if(lik >= ranks[i].required_like_count && lik < ranks[i+1].required_like_count && i != ranks.length) {
$(lnk).after('<br />'+ranks[i].rank);
}
Is supposed to trigger when the number of likes is more than or equal to the amount required to get that rank and less than the amount required for the next rank.
My problem is that only the first part seems to be working. The first rank starts at 0 and works fine, but once a user gets one like (which I have set to be the second rank right now...) the system throws an error: ""An error occurred during a document.ready call: " "TypeError: pb.plugin.get(...).settings.ranks[(i + 1)] is undefined" ""
I am afraid this is some sort of simple error, but I am currently not able to see it nor is my brother (he didn't have much time to look however...) does anyone know where I have gone wrong? Thanks for the help and your time!