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
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
} 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.