Tell us what’s happening:
My code seems to run fine, but doesn’t pass the test.
- When the array has less than three of the same number, your getHighestDuplicates function should update the final radio option with
", score = 0"
I’m not sure where I have gone wrong. I have already tried moving the updateRadioOption(5,0)
to the else
bracket but it didn’t change anything.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const getHighestDuplicates = () => {
for (let i = 0; i < diceValuesArr.length - 1; i++) {
let count = 1;
for (let j = i + 1; j < diceValuesArr.length; j++) {
if (diceValuesArr[i] == diceValuesArr[j]) {
count++;
}
}
updateRadioOption(5, 0);
if (count > 3) {
score = diceValuesArr.reduce((acc, currVal) => acc + currVal, 0);
updateRadioOption(1, score);
updateRadioOption(0, score);
scoreInputs.value = score;
scoreSpans.textContent = `, score = ${score}`
}
else if (count == 3) {
score = diceValuesArr.reduce((acc, currVal) => acc + currVal, 0);
updateRadioOption(0, score);
scoreInputs.value = score;
scoreSpans.textContent = `, score = ${score}`
}
else {
scoreInputs.value = 0;
scoreSpans.textContent = ", score = 0"
}
}
}
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
getHighestDuplicates();
updateStats();
}
});
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.1 Safari/605.1.15
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7