Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
¿Por qué mi código se ejecuta en cada caso de interruptor en lugar de romperse?

El código está diseñado para tomar dos argumentos que escribo cuando llamo a playRound en la consola. Cuando pongo 'rock' como playerSelection y computerSelection, ejecuta todo el código en el caso de playerSelection 'rock', por ejemplo, ambos eligieron rock. ¡Es un empate! Elegiste rock y la CPU eligió rock. . . ¡Tú ganas! Elegiste rock y la CPU eligió rock. . . ¡Tú pierdes!

 function playRound(playerSelection, computerSelection) { // LINE BELOW IS COMMENTED OUT FOR TESTING // playerSelection = window.prompt("Rock, paper, or scissors?") // Conditional statement to have different outcomes depending on player selection switch (playerSelection) { case 'rock': // conditional outcomes depending on computer selection after player selects rock switch (computerSelection) { case 'rock': console.log(`You both chose ${playerSelection} It's a draw!`); break; case 'paper': console.log(`You chose ${playerSelection} and the CPU chose ${computerSelection}. . . You lose!`); break; case 'scissors': console.log(`You chose ${playerSelection} and the CPU chose ${computerSelection}. . . You win!`); break; } // condition outcomes if player selects paper case 'paper': // conditional outcomes depending on computer selection after player selects rock switch (computerSelection) { case 'paper': console.log(`You both chose ${playerSelection} It's a draw!`); break; case 'scissors': console.log(`You chose ${playerSelection} and the CPU chose ${computerSelection}. . . You lose!`); break; case 'rock': console.log(`You chose ${playerSelection} and the CPU chose ${computerSelection}. . . You win!`); break; } case 'scissors': // conditional outcomes depending on computer selection after player selects scissors switch (computerSelection) { case 'scissors': console.log(`You both chose ${playerSelection} It's a draw!`); break; case 'rock': console.log(`You chose ${playerSelection} and the CPU chose ${computerSelection}. . . You lose!`); break; case 'paper': console.log(`You chose ${playerSelection} and the CPU chose ${computerSelection}. . . You win!`); break; } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No tiene un descanso en la declaración de cambio más externa.

 switch (playerSelection) { case 'rock': // conditional outcomes depending on computer selection after player selects rock switch (computerSelection) { case 'rock': console.log(`You both chose ${playerSelection} It's a draw!`); break; case 'paper': console.log(`You chose ${playerSelection} and the CPU chose ${computerSelection}. . . You lose!`); break; case 'scissors': console.log(`You chose ${playerSelection} and the CPU chose ${computerSelection}. . . You win!`); break; } break;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!