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));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));Te faltan paréntesis -> .toLowerCase()
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í.