代码:
let stars = '★★★★★☆☆☆☆☆';
//一颗星
let rate1 = 1;
let star1 = stars.slice(5 - rate,10 - rate);
console.log(star1) //'★☆☆☆☆'
//两颗星
let rate2 = 2;
let star2 = stars.slice(5 - rate,10 - rate);
console.log(star2) //'★★☆☆☆'
//三颗星
let rate3 = 3;
let star3 = stars.slice(5 - rate,10 - rate);
console.log(star3) //'★★★☆☆'
//四颗星
let rate4 = 4;
let star4 = stars.slice(5 - rate,10 - rate);
console.log(star4) //'★★★★☆'
//五颗星
let rate5 = 5;
let star5 = stars.slice(5 - rate,10 - rate);
console.log(star5) //'★★★★★'
网友评论