Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
getting an error while running my shuffle builddeck (explanation below)

Shuffling your deck

  1. Use a function declaration to create a function called shuffle that takes deck as an argument.
  2. Inside this function create a variable called "shuffledDeck" that takes deck as its value.
  3. Using "let" declare three new variables: currentIndex, whos value should equal the length of the deck array, and two more:
    • temporaryValue and randomIndex,
    • each of which should currently have no value assigned.
  4. Create a while loop whos condition is that "currentIndex" does not equal 0, so that we stop looping once we've gone through all 52 cards.
  5. Inside the while loop, use the javascript Math.methods to generate a random integer between 0 and "currentIndex"
  6. Inside the while loop, decrement current index by 1. (should be after step 9)
  7. Inside the while loop, assign "temporaryValue" with "shuffledDeck" (which is an array) to the [currentIndex].
  8. Still inside, assign "shuffledDeck[currentIndex]" a value of shuffledDeck to the [randomIndex]
  9. Still inside, assign "shuffledDeck[randomIndex]" a value of "temporaryValue". (currentIndex //i--;)
  10. Review the code from steps 7,8, and 9, and leave a comment explaining what you believe those lines of code are doing as they swap assignments of values between them.
  11. Finally, close the while loop and return "shuffledDeck". You should now be able to run shuffle(buildDeck()) in node and see your shuffled deck of cards.

Here is my code

function shuffle (deck) {
    let shuffleDeck = deck;
    let currentIndex = deck.length;
    let temporaryValue, randomIndex;

    while (currentIndex != 0) {
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;
        temporaryValue = shuffleDeck[currentIndex];
        shuffleDeck[randomIndex] = temporaryValue;
    }

    return shuffleDeck;
}

I'm super new to coding so I'm just confused

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda