This forum is now read-only. Please use our new forums! Go to forums
Rock paper scissors 3/9 whats wrong?
var userChoice=prompt(“Do you choose rock, paper or scissors?”); var computerChoice = Math.random(); console.log(computerChoice) if (computerChoice===0-0.33===”rock”) { console.log(“computer:” computerChoice) } else if (computerChoice===0.34-0.66===”paper”) { console.log(“computer:” computerChoice) } else { (computerChoice===0.67-1===”scissors”) console.log(“computer:”computerChoice) };
Answer 55c9ba829113cbae27000199
4 votes
Exercise 3/9 correct code should like this:
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
Exercise 4/9 correct code should look like this:
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice < 0.33) {
computerChoice = "rock";
} else
if (computerChoice < 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
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
3 comments
console.log(computerChoice) needs removing from where you have it because at that point computerChoice is just equal to a floating point number. The variable is not yet allocated a string term.
The correct code should have the console.log(computerChoice); statement after the if/else statement because at this point the variable computerChoice has been given the string (IE: what the computer has chosen).
Thanks alot
thanks. this helped!