Read Write Dataset displaying entry on user input fields and Ratings capture & display coding error

The tutorial that you are using is only using code in the frontend on the page that you are using it.

It does not use any backend file so in theory there should be no issues with any js or jsw backend files with this tutorial.

The code is simply as this on your page which you simply paste underneath the export function for your ratingsInput_change event as stated in the tutorial.
Copy the code below and paste it into the event handler function above the line that says “//Add your code for this event here:”. (You can delete that line if you want.)

$w.onReady(function() {

export function ratingsInput1_change(event){
$w("#dataset1").onReady(() => {
// get the current item from the dataset
constcurrentItem = $w("#dataset1").getCurrentItem();

// get the current average rating, number of ratings, and
//total ratings for the current dataset item
constaverage = currentItem.avg;
constcount = currentItem.numRatings;
consttotal = currentItem.totalRatings;

// get the new rating from the ratings input
constnewRating = $w('#ratingsInput1').value;

// calculate the new average rating based on the current
//average and count
constnewAverageLong = (total + newRating) / (count +1);
// Round the average rating to 1 decimal point
constnewAverageShort = Number.parseFloat(newAverageLong).toFixed(1);

// set the dataset fields to the new average, total
// ratings, and number of ratings
$w('#dataset1').setFieldValues({
'avg': newAverageShort,
'totalRatings': total + newRating,
'numRatings': (count + 1)
});

// save the dataset fields to the collection
$w('#dataset1').save()
.catch((err) => {
console.log('could not save new rating');
});
});
});

Plus, make sure that you have setup the database for this as stated in the tutorial too with the correct field types.

In your collection

  1. Make sure your collection’s permissions allow for user input.

  2. Add 3 new Number fields, for the average rating, number of ratings submitted, and sum of all the ratings submitted. You can leave these fields blank or input a starting values. Remember that the average rating must be between 1 and 5.