Help me with the "Rock", "Scissors" and "Paper" exercise

Hi everyone,
My name is Divya and I am new to this community.

I am learning JavaScript coding as I want to learn a coding language. I am not from a technical background and this my first time learning coding. I am stuck on the “Rock”, “Scissors” and “Paper” exercise - 3part - declaring winners.

I have seen the hints given by Codecademy, yet I’m not sure what do to next -

let userOne = "Divya"; const userTwo = "Computer"; console.log( `Welcome to the game, ${userOne} and ${userTwo}!. May the best player win.` ); let randomNumberOne = Math.floor(Math.random() * 3); let userOneChoice = ""; switch (randomNumberOne) { case 0: userOneChoice = "Scissors"; break; case 1: userOneChoice = "Rock"; break; case 2: userOneChoice = "Paper"; break; } let randomNumberTwo = Math.floor(Math.random() * 3); let userTwoChoice = ""; switch (randomNumberTwo) { case 0: userTwoChoice = "Scissors"; break; case 1: userTwoChoice = "Rock"; break; case 2: userTwoChoice = "Paper"; break; } console.log(`${userOne} : ${userOneChoice}This text will be hidden ${userTwo} : ${userTwoChoice}`); if (randomNumberOne === randomNumberTwo) { return "The game is a tie!"; }

Could someone please review my code and let me what should I do next

Thank you

I had also some trouble with here is my code it is not the best but it might help you if

if (userChoice === computerChoice) { return 'the game was tie'; } if(userChoice === 'rock') { if (computerChoice === 'paper') { return 'Computer won!'; } else { return 'User won!'; } } else if (userChoice === 'paper') { if (computerChoice === 'scissors') { return 'Computer won!'; } else { return 'User won!'; } } else if (userChoice === 'scissors') { if (computerChoice === 'rock') { return 'Computer won!'; } else { return 'User won!'; } }

Thank you sharing. I am really close to the right output, however, getting it wrong in cases of tie.

[codebyte]

let userOne = "Divya"; const userTwo = "Computer"; console.log( `Welcome to the game, ${userOne} and ${userTwo}!. May the best player win.` ); let randomNumberOne = Math.floor(Math.random() * 3); let userOneChoice = ""; switch (randomNumberOne) { case 0: userOneChoice = "Scissors"; break; case 1: userOneChoice = "Rock"; break; case 2: userOneChoice = "Paper"; break; } let randomNumberTwo = Math.floor(Math.random() * 3); let userTwoChoice = ""; switch (randomNumberTwo) { case 0: userTwoChoice = "Scissors"; break; case 1: userTwoChoice = "Rock"; break; case 2: userTwoChoice = "Paper"; break; } console.log(`${userOne} : ${userOneChoice} ${userTwo} : ${userTwoChoice}`); if (userOneChoice === "Rock") { if (userTwoChoice === "Paper") { console.log(`${userTwo} wins!`); } else { console.log(`${userOne} wins!`); } } else if (userOneChoice === "Paper") { if (userTwoChoice === "Scissors") { console.log(`${userTwo} wins!`); } else { console.log(`${userOne} wins!`); } } else if (userOneChoice === "Scissors") { if (userTwoChoice === "Rock") { console.log(`${userTwo} wins!`); } else { console.log(`${userOne} wins!`); } } else if (userOneChoice === userTwoChoice) { console.log("It is a tie!"); } else { console.log("We have a winner!"); }

You will be fine as you more practice I feel the same for myself, however you may find out other ways of solving the problems the more you go further, I revisited my code and rewrite it with my understanding of later practice check my code you will see it will become more and more better

// array of choices const arr = ['rock', 'paper', 'scissors']; // computer's choice const getComputerChoice = () => { let random = Math.floor(Math.random() * 3); return arr[random]; } //user's choice const getUserChoice = userInput =>{ userInput = userInput.toLowerCase(); for (const check of arr){ if(check === userInput) { return userInput } else { return console.log('type: rock, paper, scissors') } } } // determine winner const determineWinner = (userChoice, computerChoice) => { if (userChoice === computerChoice){ return "The game is TIE!" } else if ((userChoice === 'rock' && computerChoice === 'scissors') || (userChoice === 'paper' && computerChoice === 'rock') || (userChoice === 'scissors' && computerChoice === 'paper')) { return "User WON!" } else { return "Computer WON!" } } //run the game /*const playGame = () => { const user = getUserChoice('rock'); const comp = getComputerChoice(); console.log('User - ' + user) console.log('Comp - ' + comp) console.log(determineWinner(user, comp)) } playGame() */ //automate the game in console const randomUser = Math.floor(Math.random() * 3); const playGame = () => { const user = arr[randomUser]; const comp = getComputerChoice(); console.log('User - ' + user) console.log('Comp - ' + comp) console.log(determineWinner(user, comp)) } playGame()
} else if (userOneChoice === userTwoChoice) {
  console.log("It is a tie!");

You check whether the user’s choice and the computer’s choice are the same after checking for rock, paper, or scissors.
But this should probably be before those instead.