Tell us what’s happening:
Test 17 won’t pass at all. Just wondering what the issue is. Thanks.
Your code so far
let poll = new Map();
function addOption(option) {
if (option && poll.has(option)) {
return `Option "${option}" already exists.`
} else if (option && !poll.has(option)) {
poll.set(option, new Set())
return `Option "${option}" added to the poll.`
} else {
return `Option cannot be empty.`
}}
function vote(option, voterId) {
const bool = poll.get(option)
if (bool && !bool.has(voterId)) {
poll.set(option, poll.get(option).add(voterId))
return `Voter ${voterId} voted for "${option}".`
} else if (bool && bool.has(voterId)) {
return `Voter ${voterId} has already voted for "${option}".`
} else {
return `Option "${option}" does not exist.`
}
}
addOption("Malaysia");
addOption("Turkiye");
addOption("Egypt");
vote("Malaysia", "Ryan")
vote("Turkiye", "Bob")
vote("Turkiye", "Netenyahu")
vote("Turkiye", "James")
vote("Egypt", "Robbie")
vote("Egypt", "Gregor")
function displayResults() {
let result = []
let resultStr = ''
poll.forEach((value, key) => {
result.push(`${key}: ${value.size} votes`)
})
for (const char of result) {
resultStr += char + "\n"
}
return "Poll Results:\n" + resultStr
}
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/143.0.0.0 Safari/537.36
Challenge Information:
Build a Voting System - Build a Voting System