# Review Algorithmic Thinking by Building a Dice Game - Step 7

**URL:** <https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/743425>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [April 14, 2025, 12:35pm UTC](https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/743425 "2025-04-14T12:35:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aryaanchauhan01](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aryaanchauhan01/32/324744_2.png) [@aryaanchauhan01](https://forum.freecodecamp.org/u/aryaanchauhan01)\
**Post date:** [April 14, 2025, 12:35pm UTC](https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/743425/1 "2025-04-14T12:35:18Z")

</div>

### Tell us what’s happening:

It is showing the following error, even though I kept the condition for less then 3

When the array has less than three of the same number, your getHighestDuplicates function should update the final radio option with , score = 0.

### Your code so far

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

```

```css
/* file: styles.css */

```

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

function getHighestDuplicates(arr){
  let count={};
  let score=0
  arr.forEach(num=>{
    count[num]=(count[num]||0)+1;
    score+=num;
  });

  count.forEach(num=>{
    if(n>=4){
      updateRadioOption(1,score);
    }else if(n>=3){
      updateRadioOption(0,score);
    }else if(n<3){
      updateRadioOption(5,0);
    }
      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(arr);
  }
});

// User Editable Region

```

### Your browser information:

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36`

### Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/review-algorithmic-thinking-by-building-a-dice-game/step-7)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![MostafaElbadry](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@MostafaElbadry](https://forum.freecodecamp.org/u/MostafaElbadry)\
**Post date:** [April 14, 2025, 1:40pm UTC](https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/743425/2 "2025-04-14T13:40:18Z")

</div>

You’re on the right way, just missing a few small things.

* * *

> [@aryaanchauhan01](#):
>
> ```js
> count.forEach(num=>{
> if(n>=4){
> updateRadioOption(1,score);
> }else if(n>=3){
> updateRadioOption(0,score);
> }else if(n<3){
> updateRadioOption(5,0);
> }
> updateRadioOption(5,0);
>     
> });
> 
> ```

- What is `n` ?

- `count` is an object. So, is the `forEach` method considered an array method or an object method ?

- The challenge requires:

* * *

> [@aryaanchauhan01](#):
>
> ```js
> else {
> rolls++;
> rollDice();
> updateStats();
> getHighestDuplicates(arr);
> }
> 
> ```

`arr` doesn’t exist in the global scope, it’s defined as a parameter inside the `getHighestDuplicates` function.

---

<div class="post-metadata">

**Author:** ![aryaanchauhan01](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aryaanchauhan01/32/324744_2.png) [@aryaanchauhan01](https://forum.freecodecamp.org/u/aryaanchauhan01)\
**Post date:** [April 14, 2025, 2:31pm UTC](https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/743425/3 "2025-04-14T14:31:44Z")

</div>

I updated it as follows

```js
function getHighestDuplicates(){
  let count={};
  let score=0
  diceValuesArr.forEach(num=>{
    count[num]=(count[num]||0)+1;
    score+=num;
  });

  for(let n in count){
    if(n >= 4){
      updateRadioOption(1, score);
    }else if(n >= 3){
      updateRadioOption(0, score);
    }
    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();
  }
});

```

but I am still getting the same error,  
When the array has less than three of the same number, your `getHighestDuplicates` function should update the final radio option with `, score = 0` .

The earlier points were really helpfull, thank you.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [April 14, 2025, 2:35pm UTC](https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/743425/4 "2025-04-14T14:35:01Z")

</div>

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [April 14, 2025, 2:35pm UTC](https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/743425/5 "2025-04-14T14:35:57Z")

</div>

> create a `getHighestDuplicates` function which takes an array of numbers.

I am not sure your function takes an array of numbers

---

<div class="post-metadata">

**Author:** ![MostafaElbadry](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@MostafaElbadry](https://forum.freecodecamp.org/u/MostafaElbadry)\
**Post date:** [April 14, 2025, 2:36pm UTC](https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/743425/6 "2025-04-14T14:36:10Z")

</div>

> [@aryaanchauhan01](#):
>
> ```js
> for(let n in count){
> 
> ```

any object has `key: value` pairs, so which of them is `n` ?

> [@aryaanchauhan01](#):
>
> ```js
> else {
> rolls++;
> rollDice();
> updateStats();
> getHighestDuplicates();
> }
> 
> ```

Why did you call the function without any argument ?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [October 14, 2025, 2:36am UTC](https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/743425/7 "2025-10-14T02:36:11Z")

</div>

Closed on October 14, 2025, 2:36am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
