Photos/screenshots of an error can be helpful, but it also helps to provide the complete code. Posting the code helps us help you better!
When you enter a code, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
I’m trying to find out what went wrong with my code for the detectFullHouse function. Below is my code:
const detectFullHouse = () => {
let counts = {};
listOfAllDice.forEach(die => {
let value = die.textContent;
counts[value] = (counts[value] || 0) + 1;
});
let values = Object.values(counts);
if (values.includes(3) && values.includes(2)) {
let thirdRadioButton = Array.from(scoreInputs)[2];
thirdRadioButton.value = 25;
thirdRadioButton.disabled = false;
scoreSpans[2].textContent = `, score = 25`;
} else {
let lastRadioButton = Array.from(scoreInputs)[scoreInputs.length - 1];
lastRadioButton.value = 0;
lastRadioButton.disabled = false;
scoreSpans[scoreSpans.length - 1].textContent = `, score = 0`;
}
};
After clicking the Check Your Code button, I get this message:
When a full house is rolled, your detectFullHouse
function should enable the third radio button, set its value to 25
, and set the third span
to display the text , score = 25
.
My code looks okay to me. Any helpful hints would be appreciated.
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
Please also include a link to the challenge.
This helps us to read it and understand the context of your question.
They are expecting you to use a function that you created in an earlier step to update the radio buttons.
I’ve updated the code to use a function like you said but am still getting the same error message after clicking the Check Your Code button.
Here is my code for the detectFullHouse function:
const detectFullHouse = () => {
let counts = {};
Array.from(listOfAllDice).forEach(die => {
let value = die.textContent;
counts[value] = (counts[value] || 0) + 1;
});
let values = Object.values(counts);
if (values.includes(3) && values.includes(2)) {
updateRadioOption(2, 25)
} else {
updateRadioOption(5, 0)
}
};
Can you include a link to the step so we can read the instructions?
Also, I recall that the last radio button has to be updated all the time in this function so just do that without checking the if statement condition.
here’s the link: Review Algorithmic Thinking by Building a Dice Game: Step 13 | freeCodeCamp.org
I tried updating the last radio button without checking the if statement and I am still getting the same error message.
any reason why you’re not using the diceValuesArr ?
Edit: it looks like they are expecting you to pass the diceValuesArr to the function and use it. (so detectFullHouse should be expecting an array as an argument)
I appreciate your suggestion but as you can see from the screenshot, I’m still getting the same message even after passing the diceValuesArr to the detectFullHouse function and using it as an array instead of using the Array.from(listOfAllDice)
the array is an array of numbers?
So you cannot get the textContent from an array of numbers.
Also the last radio button should be updated regardless of the checks you are doing.
Edit: try to check the console and add some logs to see what is happening.
You can log the array for example and log the counts.
Thank you so much! You’ve been an excellent help