Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

Working in local environment but not passing tests. Also the textContent is not updating in the freeCodeCamp preview browser, where as it is in my local environment

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = () => {
    numObj = {};
    sum = 0;

    for (let i = 0; i < diceValuesArr.length; i++) {
        const value = diceValuesArr[i];
        if (numObj[value] === undefined) {
            numObj[value] = 1;
        } else {
            numObj[value] += 1;
        }
        sum += value;
    }

    // flag for match
    let found = false;

    // four of a kind
    for (const key in numObj) {
        if (numObj[key] === 4) {
            updateRadioOption(1, sum);
            found = true;
            break;
        }
    }

    // three of a kind
    if (!found) {
        for (const key in numObj) {
            if (numObj[key] === 3) {
                updateRadioOption(0, sum);
                found = true;
                break;
            }
        }
    }

    // Others
    if (!found) {
        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

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

create a getHighestDuplicates function which takes an array of numbers.

Sounds like it needs to take an array as a parameter.

Hi there!
You are calling the function within event listener call back function. The instructions is asked you different things to do. Read the instructions carefully and remember you need to add your new code in empty line on the challenge editor, just before your rollDiceBtn event listener.

Thank you both for the tips. I got it working eventually. Just not sure, as I said, why functionally it was working fine in my local environment. I suppose behind the scenes the testing was a bit stricter. Nonetheless thanks

2 Likes

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