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

257
Views
¿Cómo puedo hacer que mi función devuelva un valor que no sea indefinido?

Estoy tratando de completar el desafío de piedra, papel o tijera de The Odin Project. Estoy atascado; No sé por qué cuando ejecuto mi código, mi función playRound devuelve indefinido. Cualquier ayuda sería apreciada.

 const computerPlay = () => { //Randomly returns 'Rock', 'Paper', or 'Scissors' let choices = ['rock', 'paper', 'scissors']; let computerChoice = choices[Math.floor(Math.random() * choices.length)]; return computerChoice; } const playRound = (playerSelection, computerSelection) => { playerSelection = playerSelection.toLowerCase; if (playerSelection === computerSelection) { return "It's a tie"; } else { switch (playerSelection.toLowerCase) { case 'rock': switch (computerSelection) { case 'paper': return "You Lose! Paper beats Rock"; case 'scissors': return "You Win! Rock beats Scissors"; } case 'paper': switch (computerSelection) { case 'rock': return "You Win! Paper beats Rock"; case 'scissors': return "You Lose. Scissors beats Paper" } case 'scissors': switch(computerSelection) { case 'rock': return "You Lose. Rock beats scissors"; case 'paper': return "You Win. Scissors beats Paper" } } } } const playerSelection = "rock"; const computerSelection = computerPlay(); console.log(playRound(playerSelection, computerSelection));
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Te faltan paréntesis en el método toLowerCase .

 const computerPlay = () => { //Randomly returns 'Rock', 'Paper', or 'Scissors' let choices = ['rock', 'paper', 'scissors']; let computerChoice = choices[Math.floor(Math.random() * choices.length)]; return computerChoice; } const playRound = (playerSelection, computerSelection) => { playerSelection = playerSelection.toLowerCase(); if (playerSelection === computerSelection) { return "It's a tie"; } else { switch (playerSelection.toLowerCase()) { case 'rock': switch (computerSelection) { case 'paper': return "You Lose! Paper beats Rock"; case 'scissors': return "You Win! Rock beats Scissors"; } case 'paper': switch (computerSelection) { case 'rock': return "You Win! Paper beats Rock"; case 'scissors': return "You Lose. Scissors beats Paper" } case 'scissors': switch(computerSelection) { case 'rock': return "You Lose. Rock beats scissors"; case 'paper': return "You Win. Scissors beats Paper" } } } } const playerSelection = "rock"; const computerSelection = computerPlay(); console.log(playRound(playerSelection, computerSelection));

over 4 years ago · Santiago Trujillo Report

0

Te faltan paréntesis -> .toLowerCase()

over 4 years ago · Santiago Trujillo Report

0

const sentence = 'My Dog Is Brown'; console.log(sentence.toLowerCase()); // expected output: "my dog is brown"

El método .toLowerCase() devuelve el valor de la cadena convertida a minúsculas.
.toLowerCase() no afecta el valor de la cadena en sí.

over 4 years ago · Santiago Trujillo 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!