Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda