What is wrong with my meteor leaderboard example? -
I have just installed the meteor and I have a look at the leaderboard example.
I am trying to set a random score, can not see what is wrong with my code, is there anything wrong with this? I hope that when the button is clicked, the selected player score is populated with a random number.
Template code:
& lt; Template Name = "Leaderboard" & gt; & Lt; Div class = "leaderboard" & gt; {{#each player}} {{& gt; Player}} {{/ every}} & lt; / Div & gt; {{#if select_name}} & lt; Div class = "description" & gt; & Lt; Div class = "name" & gt; {{Selected_name}} & lt; / Div & gt; & Lt; Input type = "button" class = "inc" value = "5 points" / & gt; & Lt; Input type = "button" square = "incrandom" value = "set random point" /> & Lt; / Div & gt; {{Else}} & lt; Div class = "none" & gt; Select & lt; / Div & gt; {{/ If}} & lt; / Template & gt;
JS code:
Template.leaderboard.events ({click on 'input.incrandom': function () {players.update (session. Get ("selected_pluger"), {$ inkramdom: {Score: Math.flur (Random Fraction () * 10) * 5}});}}};
There is no $ incrandom
operator in MongoDB only.
In addition, in this code snippet What is random
? You probably wanted to use Math.random ()
. . Also (thank you @ pendua, I did not pay attention), < Cod E> Session should be Session
.
Then the updated code will be:
Template.leaderboard.events ({'input. Click on incrandom ': function () {players.update (session.get ("selected_player"), {$ inc: {score: Math.floor (Math.rendum (* * 10) * 5}});}} );
However, note that this does not set the player's score to a random value, but increments From the random value to the score
Use the operator instead of setting the player's score.
Comments
Post a Comment