Preview reads 'script error.' What could I be missing? Script/instructions taken from https://support.wix.com/en/article/wix-code-tutorial-capturing-and-displaying-ratings
export function ratingsInput1_change(event) { $w('#dataset2').onReady(() => { // get the current item from the dataset const currentItem = $w("#dataset2").getCurrentItem(); // get the current average rating, number of ratings, and //total ratings for the current dataset item const average = currentItem.average; const count = currentItem.numberSubmitted; const total = currentItem.sum; // get the new rating from the ratings input const newRating = $w('#ratingsInput1').value; // calculate the new average rating based on the current //average and count const newAverageLong = (total + newRating) / (count +1); // Round the average rating to 1 decimal point const newAverageShort = Number.parseFloat(newAverageLong).toFixed(1); // set the dataset fields to the new average, total // ratings, and number of ratings $w('#dataset2').setFieldValues({ 'average': newAverageShort, 'sum': total + newRating, 'numberSubmitted': (count + 1) }); // save the dataset fields to the collection $w('#dataset2').save() .catch((err) => { console.log('could not save new rating'); }); }); //Add your code for this event here: }
See this complete example:
Ratings Input and Display
Let users rate recipes and display the rating results.