-5
I’m a beginner in programming and discovered a site play to start the codeacademy, but they have some errors and maybe making my understanding difficult.
I am in the following javascript exercise:
Computer Choice: Part 2 We have computerChoice, but it is now equal to a random number between 0 and 1. We need to somehow translate this random number into a choice between stone, paper and scissors. How do we do this?!
If computerChoice is between 0 and 0.33, computerChoice equal to "stone". If computerChoice is between 0.34 and 0.66, do computerChoice equals "paper". If computerChoice is between 0.67 and 1, computerChoice equal to "scissors". But there are three results! If / Else allows us only two results. And now?! We need to use if / Else if / Else. Read the hint for the full syntax. You will find grace so easy she is.
Instructions Under your existing code, write the if / Else statement if / Else In the respective code blocks, change the value of computerChoice based on the above rules. Remember, you DO NOT need use var when changing the value of an existing variable.
Detail: They didn’t teach me to do if else
along.
I have to play a little game of rock, paper and scissors following these instructions.
Follow how I wrote the code:
var userChoice = prompt("Você escolhe pedra, papel ou tesoura?");
var computerChoice = Math.random();
console.log (computerChoice);
if (computerChoice <= 0.33) {
console.log("Pedra");
} else if (computerChoice Não sei o que colocar aqui (tem alguma função "entre") {
console.log("Papel");
} else (computerChoice > 0.67) {
console.log("Tesoura");
}
If you can help me to advance my course!
The "between" condition in your case is: greater than 0.34 and less than 0.66.
– Taisbevalle
This question has two votes closing as wide as too. Although this is certainly not one of our better questions, I disagree with the closing votes. This question has nothing broad in it (on the contrary, it is very restricted, since it is a question about a single line of code). In addition, I believe that the other reasons for closure do not apply (it is not duplicate, it is about programming, it is not opinionated, the question is clear, it is not a typo, it is reproducible and it is in Portuguese).
– Victor Stafusa