hi, using a screen reader jaws for windows 2025 and using windows 11 2025. google chrome 144. now totally blind. doing the build a voting system. and steps 5,6 and 17 are falling over or failing. reset the lesson a few times and done a hard refresh a couple of times. so can any one help. is it my code, or the way fcc tests. so what is fcc tests looking for. can you explain, and then help me out to get it to pass. pasting the java script below for steps 5,6, and 17. and then the errors and the lab.
thank you.
marvin.
java script:
// Voting System JS - forum sample (steps 5,6,17 failing)
const poll = new Map();
function addOption(option) {
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.;
}
function vote(option, voterId) {
if (!poll.has(option)) return Option "${option}" does not exist.;
const voters = poll.get(option);
if (voters.has(voterId)) return Voter ${voterId} has already voted for "${option}".;
voters.add(voterId);
return Voter ${voterId} voted for "${option}".;
}
function displayResults() {
let results = “Poll Results:”;
poll.forEach((voters, option) => {
results += \n${option}: ${voters.size};
});
return results;
}
// No prepopulation: FCC tests will add options and votes
errors:
-
Passed:1. You should have a
pollvariable initialized to a newMapobject. -
Passed:2. You should define a function
addOptionthat accepts a parameteroption. -
Passed:3. You should define a function
votethat accepts two parameters,optionandvoterId. -
Passed:4. You should define a function
displayResultsto display the poll results. -
Failed:5. You should have at least three options in your
poll. -
Failed:6. Your
pollshould have at least three votes. -
Passed:7. You should ensure each voting option maps to a
Setobject. -
Passed:8.
addOption("Egypt")should returnOption "Egypt" added to the poll. -
Passed:9. Adding an empty option should return
"Option cannot be empty." -
Passed:10. When
Turkeyis already added,addOption("Turkey")should returnOption "Turkey" already exists. -
Passed:11. When
Malaysiaexists in the voting options,vote("Malaysia", "traveler1")should returnVoter traveler1 voted for "Malaysia". -
Passed:12.
voteshould update theSetof voters for an option. -
Passed:13. When
traveler1tries to vote forAlgeriaagain,vote("Algeria", "traveler1")should returnVoter traveler1 has already voted for "Algeria". -
Passed:14. Duplicate votes should not increase the size of the
Set. -
Passed:15. When
Nigeriais not in the voting options,vote("Nigeria", "traveler2")should returnOption "Nigeria" does not exist. -
Passed:16. A unique option should be able to receive multiple votes.
-
Failed:17.
displayResults()should return the results in the correct format. -
project:
-
Menu
Instructions
script.jsEditor
Console
Build a Voting System
In this lab, you will build a voting system that uses
Mapto create a poll andSetto prevent duplicate voting.Objective: Fulfill the user stories below and get all the tests to pass to complete the lab.
User Stories:
-
You should initialize a
pollvariable to a newMapobject. -
You should have a function
addOptionthat accepts a parameteroption. -
In the
addOptionfunction:-
If the
optiondoes not already exist in the poll, it should be added to the poll with an emptySetas its value to track voters. You should also return the messageOption "<option>" added to the poll. -
If the
optionalready exists, it should return the messageOption "<option>" already exists.. -
If you try to add an empty option, the function should return the message
Option cannot be empty..
-
-
You should have a function
votethat accepts two parameters,option(the option to vote for) andvoterId(a unique ID for the voter). -
In the
votefunction:-
If the
optiondoes not exist in the poll, the function should return the messageOption "<option>" does not exist.. -
If the
optionexists, the function should check if thevoterIdhas already voted for thisoption. -
If the voter has already voted, the function should return the message
Voter <voterId> has already voted for "<option>". -
If the voter has not voted,
voterIdshould be added to theSetofvotersfor this option. The function should return the messageVoter <voterId> voted for "<option>".
-
-
You should have at least three options in your
poll. -
Your
pollshould have at least three votes. -
You should have a function
displayResultsthat returns the poll results in the following format:
Poll Results: OptionA: N votes OptionB: N votes . . /* sample output Poll Results: Turkey: 2 votes Morocco: 1 votes */Run the Tests (Ctrl + Enter)
Reset this lesson
Get Help
Tests
-
Waiting:1. You should have a
pollvariable initialized to a newMapobject. -
Waiting:2. You should define a function
addOptionthat accepts a parameteroption. -
Waiting:3. You should define a function
votethat accepts two parameters,optionandvoterId. -
Waiting:4. You should define a function
displayResultsto display the poll results. -
Waiting:5. You should have at least three options in your
poll. -
Waiting:6. Your
pollshould have at least three votes. -
Waiting:7. You should ensure each voting option maps to a
Setobject. -
Waiting:8.
addOption("Egypt")should returnOption "Egypt" added to the poll. -
Waiting:9. Adding an empty option should return
"Option cannot be empty." -
Waiting:10. When
Turkeyis already added,addOption("Turkey")should returnOption "Turkey" already exists. -
Waiting:11. When
Malaysiaexists in the voting options,vote("Malaysia", "traveler1")should returnVoter traveler1 voted for "Malaysia". -
Waiting:12.
voteshould update theSetof voters for an option. -
Waiting:13. When
traveler1tries to vote forAlgeriaagain,vote("Algeria", "traveler1")should returnVoter traveler1 has already voted for "Algeria". -
Waiting:14. Duplicate votes should not increase the size of the
Set. -
Waiting:15. When
Nigeriais not in the voting options,vote("Nigeria", "traveler2")should returnOption "Nigeria" does not exist. -
Waiting:16. A unique option should be able to receive multiple votes.
-
Waiting:17.
displayResults()should return the results in the correct format.
1
2
3
4
5
6
/** * Your test output will go here */ -