Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

How do we use the updateRadioOption()
what is the meaning of error message ", score = " error 4,6,7 same message
my code does updates the 3kind radio button to score = sum, displays a number sum of dice, my console logs do work
Advance thank you!

Your code so far

<!-- file: index.html -->

/* file: script.js */
// User Editable Region

const getHighestDuplicates = () => {
  const counts = {};
  const sum = diceValuesArr.reduce((acc, el) => acc + el, 0);
  diceValuesArr.forEach((num) => {
    counts[num] = (counts[num] || 0) + 1;
  //console.log(counts)

  });
  
  
  
  const maxCount = Math.max(...Object.values(counts)); 
  //console.log(maxCount)
  //updateRadioOption(5,0);
  if (maxCount >= 4) {
    updateRadioOption(0, score = sum);
    //tried updateRadioOption(0, sum); also
    
    updateRadioOption(1, score = sum); 
    
  } else if (maxCount >= 3) {
    updateRadioOption(0, score = sum); 
  } 
    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();
    
  }
});

// User Editable Region
/* file: styles.css */

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/18.3 Safari/605.1.15

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

Hi @Dantheman1

Do not access the diceValuesArr variable directly.

Happy coding

 const getDiceValues = () => {
    return diceValuesArr;
  }
  const getHighestDuplicates = () => {
  const diceValues = getDiceValues();
  const counts = {};
  
  const sum = diceValues.reduce((acc, el) => acc + el, 0);
  diceValues.forEach((num) => {
    counts[num] = (counts[num] || 0) + 1;
  

  });
  
  
  
  const maxCount = Math.max(...Object.values(counts)); 
  
  updateRadioOption(5,0)
  if (maxCount >= 4) {
    updateRadioOption(1, score = sum);
    updateRadioOption(0, score = sum); 
    } else if (maxCount >= 3) {
    updateRadioOption(0, score = sum); 
  } else {
    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();
    
  }
});

does this help?

You need to pass it as an argument to the function call.

my changes, I have (array) my argument now? are all blocks needed here others have more blocks it is confusing ,

const getHighestDuplicates = (array) => {
    let myScore = 0;
    for (let num of diceValuesArr) {
    myScore += num;
  }
    let counts = {};
    diceValuesArr.forEach((num) => {
    counts[num] = (counts[num] || 0) + 1;
  });
  

  
    const maxCount = Math.max(...Object.values(counts)); 
  
    updateRadioOption(5,0);
  if (maxCount >= 4) {
    updateRadioOption(1, myScore);
    updateRadioOption(0, myScore); 
    } if (maxCount >= 3) {
    updateRadioOption(0, myScore); 
  } else {
    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();
    
  }
});

First, replace all refereneces to diceValuesArr with array

1 Like

This make no sense to me