Tell us what’s happening:
GRRR, ARGH! Trying to get last test on Roll Result string to read correctly. To my eyes, the output “appears” correct, but I’m failing the automated test. I’m adding \n after “Poll Results:” to get new line, and concatenating every ${key}: ${value.size} votes\n, and trimming the last \n (my last attempt), but can’t pass. GRRR, ARGH! ANY GUIDANCE MUCH APPRECIATED.
Your code so far
const newSet = new Set();
const poll = new Map([
["Turkey", newSet],
["Germany", newSet],
["United Kingdom", newSet],
["Australia", newSet],
["Algeria", newSet],
]);
poll.get("Algeria").add("traveler1");
function addOption(option) {
if (option === '') {
return 'Option cannot be empty.';
} else if (!poll.has(option)) {
const emptySet = new Set();
poll.set(option, emptySet);
return `Option "${option}" added to the poll.`
} else {
return `Option "${option}" already exists.`
}
}
console.log(addOption("Egypt"));
console.log(addOption("Egypt"));
console.log(poll)
function vote(option, voterId) {
if (!poll.has(option)) {
return `Option "${option}" does not exist.`;
//poll.set(option, voterId)
} else if (poll.has(option)) {
if (poll.get(option).has(voterId)) {
return `Voter ${voterId} has already voted for "${option}".`
} else {
poll.get(option).add(voterId);
return `Voter ${voterId} voted for "${option}".`;
}
}
}
console.log(vote("Algeria", "traveler1"))
console.log(poll.get("Algeria").has("traveler1"))
function displayResults() {
let pollString = '';
pollString += `Poll Results:\n`;
poll.forEach((val, key) => {
pollString += `${key}: ${val.size} votes\n`
})
pollString.trimEnd();
return pollString;
}
console.log(displayResults())
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Challenge Information:
Build a Voting System - Build a Voting System