简单的信誉算法 js处理

$(document).ready(function(){
// 初始化
var credit = "{sh:$info.credit}";
var res = getCreditStar(credit);
$("#show_result").text(res); // 触发事件
$("#credit").change(function(){
// 计算信誉值
var credit = parseInt($(this).val());
var res = getCreditStar(credit);
$("#show_result").text(res); }); }); // 计算荣誉标记
function getCreditStar(credit) {
credit = parseInt(credit);
var res;
if (credit <= 25) {
num = Math.floor(credit/5);
res = num+"星";
} if (credit > 25 && credit <= 125) {
num = Math.floor(credit/25);
res = num+"钻";
} if (credit > 125 && credit <= 625) {
num = Math.floor(credit/125);
res = num+"冠";
} if (credit > 625 && credit <= 3125) {
num = Math.floor(credit/625);
res = num+"皇冠";
} if (credit > 3125) {
res = 5+"皇冠";
}
return res;
}

5分一心,5心一钻,5钻一冠,5冠一皇。最高五皇。

这个是简单的处理,估计真正复杂的,到后面升级所需积分肯定越来越多。要不然升级太容易。

上一篇:javascript 数组以及对象的深拷贝(复制数组或复制对象)的方法


下一篇:面试题常考&必考之--js中的对象的浅拷贝和深拷贝(克隆,复制)(下)