Can´t make star rating to work

Can you please tell me if this code looks correct? A strange thing is that for every rate-click it updates the rating display with more than one. If it shows 5 from the start a click makes it show 9. Extremely confusing! :persevere:

export function ratingsInput1_change ( event ) {
// get the current item from the dataset
// get the current average rating, number of ratings, and
// total ratings for the current dataset item
const currentItem = $w ( “#dataset2” ). getCurrentItem ();
const average = currentItem . heterosexRating ;
const count = currentItem . heterosexNumber ;
const total = currentItem . heterosexTotal ;
const newRating = $w ( ‘#ratingsInput1’ ). value ;
const newAverageLong = ( total + newRating ) / ( count + 1 );
const newAverageShort = Number . parseFloat ( newAverageLong ). toFixed ( 1 );
$w ( ‘#dataset2’ ). setFieldValues ({
‘heterosexRating’ : newAverageShort ,
‘heterosexTotal’ : total + newRating ,
‘heterosexNumber’ : ( count + 1 )
});
$w ( ‘#dataset2’ ). save ()
console . log ( “Rating completed.” )
}