Hi, I’d just like to complain about the test conditions; specifically test 17.
The condition is that the output of displayResults(){} be formatted correctly, but it doesn’t specify where it allows a new line character, if you should instead use literal new lines, etc. This results in needing to Rube-Goldberg-Machine the returned string’s format until by some miracle (without specifying why) you pass it. Put a ‘\n’ after Poll Results: with no space? Fail. With a space? Fail. Okay, try.. (etc).
Your code so far
const createMap = () => new Map();
const poll = createMap();
const addOption = (option, map = (poll ?? createMap())) => {
if (Object.hasOwn(Object.fromEntries(map), option))
return `Option "${option}" already exists.`
if (!option)
return `Option cannot be empty.`
map.set(option, new Set())
return `Option "${option}" added to the poll.`
}
const vote = (option, voterId, map = (poll ?? createMap())) => {
if (!Object.hasOwn(Object.fromEntries(map), option)) {
return `Option "${option}" does not exist.`
}
if (!map.get(option).has(voterId)){
map.get(option).add(voterId)
return `Voter ${voterId} voted for "${option}".`
}
return `Voter ${voterId} has already voted for "${option}".`
}
const displayResults = () => {
let results = `Poll Results:`
const arr = Array.from(poll).forEach(([key, val]) => {
results += `
${key}: ${val.size} votes`
})
return results;
}
addOption("Turkey")
addOption("Algeria")
addOption("Maine")
addOption("Egypt")
vote("Egypt", "voter1")
vote("Egypt", "voter2")
vote("Egypt", "voter3")
const egypt = poll.get("Egypt")
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
Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.
We have blurred this solution (with [spoiler][/spoiler] tags) so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.