I keep getting this error: " If a small straight is rolled, your checkForStraights
function should enable the fourth radio button, set the value to 30
, and update the displayed text to , score = 30
" but on VSC in my local machine the code works perfectly!
Here is my code:
const checkForStraights = (arr) => {
let sizeOfStraights = 1;
arr.forEach((number, index) => {
let nextArrNumber = arr[index + 1];
if (number + 1 === nextArrNumber) {
sizeOfStraights ++;
}
console.log("This is the number: ", number)
console.log("This should be the next number in the array: ", nextArrNumber);
});
console.log(sizeOfStraights);
if (sizeOfStraights === 4) {
updateRadioOption(3, 30);
}
else if (sizeOfStraights === 5) {
updateRadioOption(4, 40);
}
else {
updateRadioOption(5, 0);
}
};
Please include a link to the challenge. (You can use the help button in future to create a proper post here with code and link)
1 Like
Tell us what’s happening:
I keep getting this error: “If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30, and update the displayed text to , score = 30”. Although in Visual Studio Code in my local enviroment, I am able to run the code perfektly, with the fourth radio button enabled, the value set to 30 and the text displaying “, score = 30”. Exactly as described in the exercise. What am I doing wrong?
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
};
const checkForStraights = (arr) => {
let sizeOfStraights = 1;
arr.forEach((number, index) => {
let nextArrNumber = arr[index + 1];
if (number + 1 === nextArrNumber) {
sizeOfStraights ++;
}
console.log("This is the number: ", number)
console.log("This should be the next number in the array: ", nextArrNumber);
});
console.log(sizeOfStraights);
if (sizeOfStraights === 4) {
updateRadioOption(3, 30);
}
else if (sizeOfStraights === 5) {
updateRadioOption(4, 40);
}
else {
updateRadioOption(5, 0);
}
};
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
resetRadioOptions();
rollDice();
updateStats();
getHighestDuplicates(diceValuesArr);
detectFullHouse(diceValuesArr);
checkForStraights(diceValuesArr);
}
});
// User Editable Region
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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 14
you have a few issues here.
The biggest one is the logic you are using to check for straights.
Have you tried to log the input array and see if it is working?
What is your conclusion from looking at the logs?
Edit: to be clear, I mean try to log the input array here in fcc. Then maybe add more logs as needed to see if your check is finding straights correctly. In fact it is not.