Tell us what’s happening:
I think it is working but It has not passed yet. What is wrong?
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const getHighestDuplicates = () => {
const counts = {};
diceValuesArr.forEach((value) => {
counts[value] = (counts[value] || 0) + 1;
})
const values = Object.values(counts);
const threeNumber = values.some((value) => value === 3);
const fourNumber = values.some((value) => value === 4);
const updateScore = diceValuesArr.reduce((a,b) => a+b, 0 );
if(!threeNumber && !fourNumber) {
updateRadioOption(5, 0);
} else if(threeNumber) {
updateRadioOption(0,updateScore);
} else if(fourNumber) {
updateRadioOption(1,updateScore);
}
}
// User Editable Region
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7
Do you get any error messages or hints?
1 Like
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.
Yes, this is my error message.
The instructions: “… create a getHighestDuplicates
function which takes an array of numbers. The function will need to count how many times each number is found in the array.”
Where is the required function declared?
1 Like
Do you mean I need to declare the function with parameter? Sorry, I’m confuse.
Well I put the diceValuesArr as parameter but still not pass yet but it changes the error message.
When the array has four of the same number, your getHighestDuplicates
function should update the Four of a Kind
radio option with , score =
and the total sum of the dice.
const getHighestDuplicates = (array) => {
const counts = {};
diceValuesArr.forEach((value) => {
counts[value] = (counts[value] || 0) + 1;
})
const values = Object.values(counts);
const threeNumber = values.some((value) => value === 3);
const fourNumber = values.some((value) => value === 4);
const updateScore = diceValuesArr.reduce((a,b) => a+b, 0 );
if(!threeNumber && !fourNumber) {
updateRadioOption(5, 0);
} else if(threeNumber) {
updateRadioOption(0,updateScore);
updateRadioOption(5, 0);
} else if(fourNumber) {
updateRadioOption(1,updateScore);
updateRadioOption(0,updateScore);
updateRadioOption(5, 0);
}
}
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
updateStats();
getHighestDuplicates(diceValuesArr);
}
});[quote="DucoThePaladin, post:1, topic:703624, full:true"]
### Tell us what's happening:
I think it is working but It has not passed yet. What is wrong?
### Your code so far
```html
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const getHighestDuplicates = () => {
const counts = {};
diceValuesArr.forEach((value) => {
counts[value] = (counts[value] || 0) + 1;
})
const values = Object.values(counts);
const threeNumber = values.some((value) => value === 3);
const fourNumber = values.some((value) => value === 4);
const updateScore = diceValuesArr.reduce((a,b) => a+b, 0 );
if(!threeNumber && !fourNumber) {
updateRadioOption(5, 0);
} else if(threeNumber) {
updateRadioOption(0,updateScore);
} else if(fourNumber) {
updateRadioOption(1,updateScore);
}
}
// User Editable Region
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7
[/quote]
This is my code so far. Still not pass yet TwT