Tell us what’s happening:
Last test is failing. Everything looks fine to me.
17. displayResults() should return the results in the correct format.
Your code so far
const poll = new Map();
function addOption(option) {
const voters = new Set()
if (!option) {
return "Option cannot be empty."
} else if (!poll.has(option)) {
poll.set(option, voters);
return `Option "${option}" added to the poll.`
} else {
return `Option "${option}" already exists.`
}
}
function vote(option, voterId) {
if (!poll.has(option)) {
return `Option "${option}" does not exist.`
} else if (poll.has(option)) {
if (!poll.get(option).has(voterId)) {
poll.get(option).add(voterId);
return `Voter ${voterId} voted for "${option}".`
} else {
return `Voter ${voterId} has already voted for "${option}".`
}
}
}
addOption("Russia")
addOption("Spain")
addOption("Italy")
vote("Russia", "Alex")
vote("Russia", "Nicholas")
vote("Spain", "Andrew")
vote("Italy", "Kate")
function displayResults(poll) {
let results = `Poll Results:`
poll.forEach((value, key) => {
results += `
${key}: ${value.size} votes`
})
return results
}
displayResults(poll)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Challenge Information:
Build a Voting System - Build a Voting System