Assign Badges sending a notification on every page visit; help!

So the first problem is that you have a click function that you don’t need it sounds like as you don’t want the users to have to perform an action to see their “leaderboard”

You may need to take a step back and build one part at a time to see where the error is happening.

In your page code you should first be getting the current member
then passing it to the jsw function from my tutorial to “getMemberBadges”

Once you are sure that function always returns as expected, you can move on to the next logic which sounds like…

if (userHasAllAvailableBadges) {
//do nothing
} else if (user has < AllAvailableBadges) {
//check criteria for badges user is missing
//assign whichever badge ids are missing
//refresh repeater to show newly assigned badges
}

What I would suggest is going through each step and debugging using console.log() and when each step is correct, then move on

So first make sure you are always able to get and display the users current badges on page load

Next, make sure you can identify when a user does not have all of the possible badges

Next, test your logic to check if user meets new badge criteria

Then finally if everything is working consistently so far - assign new badges (if applicable) and refresh the repeater.

Sometimes when you write ALL the code at once, it’s hard to identify the exact problem. So I would comment things out and methodically go through one piece at a time to debug the code. Debugging is really the only way to figure out where the problem is.