一直在尝试调试几个小时,但是我无法理解。
ratings = {
"hotel_a": "2.8",
};
///ratings.push ( { hotel_b : 3.2} );
console.log(ratings);
// total number of stars
const starTotal = 5;
for (const rating in ratings) {
const starPercentage = (ratings[rating] / starTotal) * 100;
const starPercentageRounded = `${(Math.round(starPercentage / 10) * 10)}%`;
document.querySelector(`.${rating}.stars - inner`).style.width = starPercentageRounded;
}
它给了我ratings.push不是函数。
///ratings.push ( { hotel_b : 3.2} );
那是行不通的,因为ratings
是对象而不是数组。
您可以做的是创建一个新的键和值。
ratings["hotel_b"] =3.2
要么
ratings.hotel_b =3.2
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句