Tell us what’s happening:
i have problem in building dice game in step 14 Step 14
For the last portion of the game, you will need to create an algorithm that checks for the presence of a straight. A small straight is when four of the dice have consecutive values in any order (Ex. 1234) resulting in a score of 30 points. A large straight is when all five dice have consecutive values in any order (Ex. 12345) resulting in a score of 40 points.
Declare a checkForStraights function which accepts an array of numbers. If the u
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const checkForStraights = (array) => {
const counts = {};
let straight = 1;
let hCount = 1;
for (const num of array) {
counts[num] = counts[num] ? counts[num] + 1 : 1;
}
const countArr = Object.keys(counts).map((key) => key);
const sortedArr = countArr.sort((a, b) => {return a - b;});
for(let i = 0; i < sortedArr.length-1; i++){
if(parseInt(sortedArr[i]) === parseInt(sortedArr[i+1]-1)){
straight += 1;
// 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/127.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14