What are y’all asking for , exactly? Is this not the way you do it?!
It’s saying “Uncaught TypeError: Cannot read properties of undefined (reading ‘reduce’).” Are we not supposed to reduce? What do we do, then? What do y’all mean, “undefined?” Everything is defined.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const getHighestDuplicates = (arr) => {
const counts = {};
let total = 0;
total = arr.reduce((acc, num) => acc + num, 0);
arr.forEach((number) => {
counts[number] = (counts[number] || 0) + 1;
});
for (let number in counts) {
if (counts[number] >= 4) {
updateRadioOption(0, total);
scoreSpans[0].textContent = `, score = ${total}`;
} else if (counts[number] >= 3) {
updateRadioOption(1, total);
scoreSpans[1].textContent = `, score = ${total}`;
} else {
updateRadioOption(5, total);
scoreSpans[5].textContent = ", score = 0";
}
}
}
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
updateStats();
getHighestDuplicates();
}
});
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7
The exercise is asking us to update the text content, though. " When the array has less than three of the same number, your getHighestDuplicates function should update the final radio option with ‘, score = 0.’
When the array has four of the same number, your getHighestDuplicates function should also update the Three of a Kind radio option with ‘, score =’ and the total sum of the dice."
I know what the function means. I still don’t get it.
I asked ChatGPT, but it’s saying to type out a bunch of new variables, which I don’t feel like doing Call me lazy, but it’s late and I’m just trying to get this done.
I kept working with it and it kept giving me some error about “Symbol.iterator” not being defined, so I changed some things around and somehow the code passed with the errors still there. I honestly don’t know what happened and I don’t care. I’m tired.
Being impatient can only help you so much with learning to code. For eg it can help drive you to search for answers faster. This can be detrimental though when one is new to the subject they are trying to learn.
Try to break down the text in the instructions into smaller sentences and even smaller phrases to analyze it before trying to code the solution. It also helps to ask a specific question on the forum. Like maybe you’ve read the text and think you know what it wants but you want to confirm your understanding first and that is great to do (in an interview, when you are given a problem to code , they would expect you to clarify the question with them verbally).
So you can come here and tell us what you believe the instructions are saying and get confirmation first and maybe that will lead to less frustration overall.
If you don’t understand the solution that worked in this step, you can also post it here between two spoiler tags and discuss it with us. Discuss the errors too. Try to take your time and resolve the concepts to your own satisfaction.
(Taking breaks is good too because learning to code is hard).
My issue is, even though I call the function, I’m getting errors concerning that function.
When the array has three of the same number, your getHighestDuplicates function should update the Three of a Kind radio option with , score = and the total sum of the dice.
hi there, welcome to the forum.
You’ve posted to someone else’s topic. Please open your own by clicking the Help button to do so (the Help button appears if you’ve unsuccessfully checked your code 3 times).
thanks