Building a Voting System

Please help needed here!
I have problem passing the following user stories of the “Building a Voting System”

  1. When Malaysia exists in the voting options, vote(“Malaysia”, “traveler1”) should return Voter traveler1 voted for “Malaysia”.

Every other option I added passed except Malaysia; I don’t know how that is possible.

  1. A unique option should be able to receive multiple votes.
    Initially, I thought it was a single vote system preventing any voter from voting twice, but as I found out it was to multiple voting system it still hasn’t passed
  2. displayResults() should return the results in the correct format. I don’t understand why this should fail as well

Please post your code and a link to the project. Also, please say which specific lines of your code you believe meet those requirements. Thanks

I have problem uploading the project, or the link. I have been searching for how to do that but I can’t. It’s like I am missing something.

I would use the Ask For Help button on the page then

Tell us what’s happening:

Please help needed here!
I have problem passing the following user stories of the “Building a Voting System” user story 11.) When Malaysia exists in the voting options, vote(“Malaysia”, “traveler1”) should return Voter traveler1 voted for “Malaysia”. User story 16.) A unique option should be able to receive multiple votes. User story 17.)displayResults() should return the results in the correct format.

Your code so far

const poll = new Map(); 

function addOption(option) {
    // Check for null, undefined, or empty/whitespace
    if (!option || option.trim() === "") {
        return "Option cannot be empty.";
    }

    if (poll.has(option)) {
        return `Option "${option}" already exists.`;
    }

    poll.set(option, new Set());
    return `Option "${option}" added to the poll.`; 
}

console.log(addOption("Egypt")); 
console.log(addOption("Turkey")); 
console.log(addOption("Malaysia"));
console.log(addOption("Algeria"));  


function vote(option, voterId) {
    if (!poll.has(option)) return `Option "${option}" does not exist.`;

    const voters = poll.get(option);

    // Check if the voter has already voted for THIS option yet it failed no. 16
    if (voters.has(voterId)) return `Voter ${voterId} has already voted for "${option}".`;

    voters.add(voterId);
    return `Voter ${voterId} voted for "${option}"`; 
}

console.log(vote("Turkey", "Clarence"));
console.log(vote("Malaysia", "Steve"));
console.log(vote("Algeria", "Cleverly"));
console.log(vote("Algeria", "Josh"));
console.log(vote("Algeria", "Trinity"));
console.log(vote("Turkey", "Prince"));
console.log(vote("Egypt", "Cajetan"));
console.log(vote("Malaysia", "traveler1")); // This logs correctly but failed no. 11. I can't say what is wrong with the code since others passed
console.log(vote("Turkey", "Trinity")); 


function displayResults() {
//This function logs correctly as the sample output, yet it failed no.17
    let result = "Poll Results:\n";

    for (const [option, voters] of poll.entries()) {
        const count = voters.size;
        const word = count === 1 ? "vote" : "votes";
        result += `${option}: ${count} ${word}\n`;  
    }
    return result;
}

console.log(displayResults());

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36

Challenge Information:

Build a Voting System - Build a Voting System

Which specific lines do you think meet the requirements?

Help!!!

I am stuck. I will appreciate any help I can get so that I move forward. I can’t detect where I got the codes wrong.

Sure, can you try to answer my question please?