javascript global.moves

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript global.moves相关的知识,希望对你有一定的参考价值。

context.global.moves = {
    
  getDist : function (_distance) {
	var distance = _distance;
	var dist = '';
	    if (distance > 1000) {
		    dist = (distance / 1000).toFixed(1) + ' km';
	    } else {
		    dist = distance + ' mtr';
	    }
	    return dist;
    },
    
    getDur : function (duration) {
    var durMinutes = (duration/60).toFixed(0);
	var dur = '';
    	if (durMinutes >= 60) {
    		dur = (durMinutes / 60).toFixed(0) + ' hr';
    		if (durMinutes % 60 > 10) {
    		   dur +=  ' ' +durMinutes % 60 + ' min';
    		}
    	} else {
    		dur = durMinutes + ' min';
    	}
	    return dur;
    },
    
    getRival: function (user) {
        var moves = [];
        var movesdb = global.get('movesdb');
        var movers = [];
        for (var i in movesdb) {
            movers.push(movesdb[i]);
        }

        var _rival = movers.slice().sort();
 
        for (var j in movers) {
            var _user = user;
            var rival = _rival.slice().sort();
            for (var k in rival) {
                if (_user.fbId == rival[k].fbId) {
                    _rival.splice(j,1);
                }
            }
            var data = {
                user: _user,
                rival: rival[0]
            };
            moves.push(_rival);
            }
    return _rival[0];
},
 
getDiff : function (newNum, oldNum) {
    var diff = newNum - oldNum;
    var diffPercent = (diff/ oldNum) * 100;
    return diffPercent;
    }
    
    
  walkStats: function(_user, _day) {
    //day = today or yesterday
    var day = _day;
    var text = "you walked " + getDistance(user[day].wDist) + " in " + getDuration(user[day].wDur) + ". "

    // if no walking
    if (user[day].wDist < 500) {
        text = insult + "You barely walked " + day + ".";
    } else {
        if (day == "yesterday") {
            text = "Yesterday " + text;
        } else {
            text = "Today " + text;
        }
    }
    return text;
}

rivalStats: function(_user, _rival) {

    var text = '';

    if (_user.wDist > _rival.wDist && _user.wDist > 500) {
        text = "You beat " + _rival.nickname + " by " + getDistance(_user.wDist - _rival.wDist) + ". ";
    } else if (_rival.wDist > 500) {
        text = insult + _rival.nickname + " beat you by " + getDistance(_rival.wDist - _user.wDist) + ". ";
    }

    return text;
}

statsCheck: function(_user, _rival, _day) {
    var text = '';

    if (_user[_day].wDist > _user.stats.average.monthly.wDist) {
        text = superword + "That's better than your monthly average of " + getDistance(_user.stats.average.monthly.wDist) + ".";
    }

    if (_user.stats.streak.num > 1) {
        text += "You are on a " + _user.stats.streak.num + " day streak.";
    } else if (_rival.stats.streak.num > 1 && _user.stats.streak.num > 1) {
        text += "You are on a " + _user.stats.streak.num + " day streak and " + _rival.nickname + " is on a " + _rival.stats.streak.num + " day streak.";
    }

    return text;
}
};

msg.payload = context.global.moves;

以上是关于javascript global.moves的主要内容,如果未能解决你的问题,请参考以下文章

javascript的题。

javascript JavaScript isset()等效: - JavaScript

JavaScript 使用JavaScript更改CSS(JavaScript)

JavaScript之基础-1 JavaScript(概述基础语法)

前端基础-JavaScript的基本概述和语法

JavaScript