This forum is now read-only. Please use our new forums! Go to forums
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:
- Ask “What do you choose…?”
- Repeat “Dog and other words aren’t valid”
- 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
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!");
}
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
2 comments
Try this code:probar este código
all you forgot was the console.log() around your compare(userChoice,computerChoice); function