The rating
question type lets the user submit a star rating.
Here's a simple example:
await form.rating("How would you rate our service today?");
Which generates a question that looks like this:
rating()
returns a number
representing the selected rating. Note that the return value is not 0-indexed, so 3/5 stars returns 3. You can use this value in the rest of your script.
let rating = await form.rating("How would you rate our service today?");
if (rating > 4) {
await form.statement("Great, we're happy to help!");
} else {
await form.long("Oh no, could you give us a bit more information, please?");
}
Using the answer from one question within the text of a subsequent question is a special case that requires a tiny bit of extra care. More details on the Interpolation page.
You can pass options to rating
like so:
rating = await form.rating("How would you rate our service today?", {max: 10});
Here's a list of all rating
-specific options:
Option | Type | |
---|---|---|
max |
number |
Total number of stars |
You can also pass global options, which are valid for all question types.