Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I believe my code is functioning properly…I know it’s not the most efficient way of doing things but it is working and when I submit it tells me that the three of a kind and four of a kind functionality isn’t working… if you copy and paste the code you can see that it is. so I’m just a bit confused.

Your code so far

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

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

};

rollDiceBtn.addEventListener("click", () => {
  diceValuesArr=[];
  scoreInputs.forEach((input)=>{input.disabled=true;
  scoreInputs.value=0; 
  });
  scoreSpans.forEach(span=>{
    span.textContent=''
  })


  
  if (rolls === 3) {
    alert("You have made three rolls this round. Please select a score.");
    
  } else {
    rolls++;
    rollDice();
    updateStats();
    getHighestDuplicates();
  }
});

const getHighestDuplicates=()=>{

  score=diceValuesArr.reduce((acc,val)=>{
      return acc+val
    },0)
  
  let one=0;
  let two=0;
  let three=0;
  let four=0;
  let five=0;
  let six=0;
  
    diceValuesArr.forEach((num)=>{
      if(num===1){
        one++
      }
      if(num===2){
        two++
      }
      if(num===3){
        three++
      }
      if(num===4){
        four++
      }
      if(num===5){
        five++
      }
      if(num===6){
        six++
      }
    }); 
    if(one===4||two===4||three===4||four===4||five===4||six===4){
      updateRadioOption(1,score);
      updateRadioOption(0,score); 
    }
    if(one===3||two===3||three===3||four===3||five===3||six===3){
      
      updateRadioOption(0,score);

    }
    if(one<3||two<3||three<3||four<3||five<3||six<3){
      updateRadioOption(5,0);
      

    }
    console.log(one,two,three,four,five,six)
    console.log(diceValuesArr)
  }




// 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/131.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

Hi there! Looks like you have modified your existing code sequence or you have created the rollDiceBtn event listener again. Reset the challenge step and try again Instead of using actual array for calculate the logic within the function getHighestFuplicate, use a parameter for the function. Then call the function getHighestDuplicate within the existingrollDiceBtn event listener callback function and use actual array diceVaiesArr as a argument.

wow. it was just the parameter and argument that was the issue…Thank You!

1 Like