Make computerChoice equal to "scissors"-doubt


I think I understand the different comparisons and how to use them, but this make it 'equal to' always gets me.
Although this next code passed, I still don't understand why did it let me pass with not only two else if's, but with wrong ranges in between the game options. Yes, you can make something less or equals to .33 and yes, you can make something bigger or equals to .67, BUT when it comes to specifying a range (I guess) I don't see how that is possible. All I see is that the code let me pass without specifying what I would imagine would exist, something like saying: else if (computerChoice from .34 - to 0.66)

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();

if (computerChoice <= 0.33) {
else if (computerChoice <= 0.33) {
else if (computerChoice >= 0.67) {

JavaScript -- RPS -- Computer Choice: Part 2

Ok there are two things in this which should have prevented this from passing:

  • using console.log instead of assigning a new value to computerChoice
  • two times <=0.33 instead of one covering the range from 0.34 to 0.66

So passing with this code is a bug.

About ranges in general. Well the idea is that you don't have to specify a range, all you need is to make sure that it stays within a range. So when you know that Math.random is naturally in the range from 0 to 1 (excluded) and you checked if it is below 0.33 than you covered the whole range from 0 to 0.33. You could as well google for boolean operators && and || which let you chain conditions but using the explained idea is all you need to pass this.