Skip to main content

Feedback Page

Welcome to the documentation for the Feedback Page! This guide will help understand the code and its features. This page is verified by: Vedant Kejariwal

Functions

This is the list of functions that are defined on this page.


Function: positive()

Description

This function sets a positive review for the producer by updating the state to indicate a positive rating and modifying the consumer's reviews for the producer.

Parameters

None

Returns

None

Code

function positive() {
setRatingStatus(1); // Updates the rating state to positive
consumerReviews[producerName] = 1; // Sets the producer's review to positive in the consumer's reviews
}

Logic Explanation

  1. Update Rating Status:

    • Sets the ratingStatus state to 1, indicating a positive review.
  2. Modify Consumer Reviews:

    • Updates the consumerReviews object to reflect the positive review for the producer.

Function: negative()

Description

This function sets a negative review for the producer by updating the state to indicate a negative rating and modifying the consumer's reviews for the producer.

Parameters

None

Returns

None

Code

function negative() {
setRatingStatus(-1); // Updates the rating state to negative
consumerReviews[producerName] = -1; // Sets the producer's review to negative in the consumer's reviews
}

Logic Explanation

  1. Update Rating Status:

    • Sets the ratingStatus state to -1, indicating a negative review.
  2. Modify Consumer Reviews:

    • Updates the consumerReviews object to reflect the negative review for the producer.

Function: UpdateWarrant()

Description

This function handles adding or removing a producer from the current challenge list. It ensures that a producer can only be challenged once and can toggle between being challenged and not being challenged.

Parameters

None (it operates on global variables like currentChallenge and producer).

Returns

None (updates the currentChallenge array directly).

Code

function UpdateWarrant() {
if (currentChallenge.indexOf(producer.name) === -1) {
currentChallenge.push(producer.name); // Add the producer to the list
player.currentChallenge = currentChallenge; // Save changes
} else {
currentChallenge = currentChallenge.filter((p) => p !== producer.name); // Remove producer
player.set("currentChallenge", currentChallenge); // Save changes
}
}

Logic Explanation

  1. Check if the producer is already in the challenge list:
  • The function uses currentChallenge.indexOf(producer.name) to determine whether the producer is already challenged.
  • If the producer is not found (-1), they are added to the currentChallenge array.
  • If the producer is found (!== -1), they are removed from the currentChallenge array.
  1. Add a producer to the challenge list:
  • The function uses currentChallenge.push(producer.name) to add the producer’s name to the array.
  1. Remove a producer from the challenge list:
  • The function uses currentChallenge.filter((p) => p !== producer.name) to create a new array without the producer’s name and update currentChallenge.
  1. Update the player's current challenge list:
  • The updated list is assigned back to player.set("currentChallenge", currentChallenge) to save the changes.