Tell us what’s happening:
please anyone help cant pass the last question and i dont know why
Your code so far
const poll=new Map()
const addOption=(option)=>{
option=option.trim()
if(option===''){
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.`;
}
console.log(addOption('Javascript'))
console.log(addOption('CSS'))
console.log(addOption('HTML'))
const 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}".`;
}
console.log(vote('Javascript','user1'))
console.log(vote('Javascript','user2'))
console.log(vote('CSS','user1'))
console.log(vote('HTML','user1'))
console.log(vote('Javascript','user1'))
const displayResults=()=>{
console.log('Poll Results:')
for(let [option,voters] of poll.entries()){
console.log(`${option}: ${voters.size} votes`)
}
}
displayResults()
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build a Voting System - Build a Voting Systemhttps://www.freecodecamp.org/learn/full-stack-developer/lab-voting-system/build-a-voting-system
ILM
August 28, 2025, 12:32pm
2
what is being returned by your function?
Poll Results:
Javascript: 2 votes
CSS: 1 votes
HTML: 1 votes
Python: 1 votes
ILM
August 28, 2025, 12:38pm
4
can you point out the return statement in your function that determines what is being returned?
`${option}: ${voters.size} votes`
ILM
August 28, 2025, 12:41pm
6
are you sure that is a return statement?
also it would be great if you could use your own words too
i dont understand but isnt that the output required?
ILM
August 28, 2025, 12:49pm
8
but is your function returning the required output? until you do that, the test fails
do you mean i should actual have the ‘return’ word in the function?
return and console.log are not the same thing at all. Important to learn the difference and make sure you are using whatever the instructions ask for.
console.log is function that logs passed in argument to console.
return is keyword, which part of the return statement, used to end function execution. Once line with it is executed, the function is exited and function returns whatever is defined in the return statement. No matter ie. if after the return was additional lines with code, or if return was within loop.
this is soo exausting…like i’ve been there for hours and this is it?i almost canceled everything
but if you use console.log in that kind of situation is there gonna be a problem?
If the instructions ask for the function to return something and you log a message to the console instead, that will not pass the test.
console.log is generally used for testing so you can see the value of a variable at a given moment in the code, or flag that a section of code is executing.
Sometimes the instructions do ask you to log something to the console so you’ll just need to pay attention for that.
Adding console.log for testing shouldn’t interfere with the tests, but it kind of depends on the test.