This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Pal
about 10 years

Next Steps (RPS) Feedback?

In the extra tasks I tried to ask the user about the game. The problem is that the game just jump from a pop up box to another, without telling the winner:

  1. Ask “What do you choose…?”
  2. Repeat “Dog and other words aren’t valid”
  3. Ask for a punctuation for the game … I thought that between 2 and 3 we could know who wins! the user or the computer… Is it normal?

This is my code, I don’t know if it is wrong:

var userChoice = prompt(“Do you choose rock, paper or scissors?”);{ if (userChoice!==”rock”,”paper”,”scissors”){ var userChoice = prompt(“IDIOTA! ROCK, PAPER OR SCISSORS?”); } }

var computerChoice = Math.random(); if (computerChoice < 0.34) { computerChoice = “rock”; } else if(computerChoice <= 0.67) { computerChoice = “paper”; } else { computerChoice = “scissors”; } var compare = function (choice1, choice2) { if(choice1===choice2){ return “The result is a tie!”; } if(choice1===”rock”){ if(choice2===”scissors”){ return “rock wins”; } else{ return “paper wins”; } } if(choice1===”paper”){ if(choice2===”rock”){ return “paper wins”; } else{ return “scissors wins”; } } if(choice1===”scissors”){ if(choice2===”rock”){ return “rock wins”; } else{ return “scissors wins”; } } }; compare (userChoice,computerChoice);

var feedback = prompt (“Qué puntuación le das a este juego?”); if (feedback>8){ console.log(“I love you”); } else{ console.log(“Rata!”); }

Answer 54a741d251b88788a70040bf

0 votes

Permalink

var userChoice = prompt("Do you choose rock, paper or scissors?");{
if (userChoice!=="rock","paper","scissors"){
var userChoice = prompt("IDIOTA! ROCK, PAPER OR SCISSORS?");
}
}

var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
var compare = function (choice1, choice2) {
if(choice1===choice2){
return "The result is a tie!";
}
if(choice1==="rock"){
if(choice2==="scissors"){
return "rock wins";
}
else{
return "paper wins";
}
}
if(choice1==="paper"){
if(choice2==="rock"){
return "paper wins";
}
else{
return "scissors wins";
}
}
if(choice1==="scissors"){
if(choice2==="rock"){
return "rock wins";
}
else{
return "scissors wins";
}
}
};
console.log(compare (userChoice,computerChoice));

var feedback = prompt ("Qué puntuación le das a este juego?");
if (feedback>8){
console.log("I love you");
}
else{
console.log("Rata!");
}
points
Submitted by Ant Hill
about 9 years

2 comments

Ant Hill about 9 years

Try this code:probar este código

Ant Hill about 9 years

all you forgot was the console.log() around your compare(userChoice,computerChoice); function