推物体给我推没有功能

肯尼

一直在尝试调试几个小时,但是我无法理解。

  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不是函数。

苏雷什·阿塔(Suresh Atta)
///ratings.push ( { hotel_b : 3.2} );

那是行不通的,因为ratings是对象而不是数组。

您可以做的是创建一个新的键和值。

ratings["hotel_b"] =3.2

要么

ratings.hotel_b =3.2

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章