#4 I don't know where the problom is


#1



https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661


It says, "Oops, try again. Did you change a computerChoice between 0.67 and 1 to 'scissors'? "


var userChoice = prompt("Do you choose rock, paper or sicissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if (0 < computerChoice < 0.33) {
    computerChoice = "rock";
} else if (0.33 <= computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "sicissors";
}
console.log(computerChoice);


#2

You spelled "scissors" wrong. Instead of "scissors", you've type "sicissors".


#3

Oh, god! Just a word!
Thank you.


#4

How does putting the if greater than 0 before and the less than 0.33 after computerChoice work exactly? I do not recall being taught in how to put a in-between this way.


#5

For a good reason too, there is no 'between' in JavaScript.

If you test that code using something like the following, you are going to see that the results are not what was intended.

var computerChoice;

// user suggested code with 'between' syntax
var between = function(choice) {
	if (0 < choice < 0.33) {
	    choice = "rock";
	} else if (0.33 <= choice <= 0.67) {
	    choice = "paper";
	} else {
	    choice = "scissors";
	}
	return choice;
};

// calculate what the computer's choice should be
// we'll ignore that the exercise doesn't say what to do with all the numbers
//   between 0.66 and 0.67
var shouldBe = function(choice) {
	if (choice < 0.33) {
	    choice = "rock";
	} else if (choice <= 0.67) {
	    choice = "paper";
	} else {
	    choice = "scissors";
	}
	return choice;
};


// let's try 100 random computeChoices using the suggested code
for (var i = 0; i <= 100; i++) {

	computerChoice = Math.random();
	console.log(computerChoice);
	console.log("Result from between function: ", between(computerChoice));
	console.log("Result from shouldBe function: ", shouldBe(computerChoice), "\n");
	
}

Try copy/pasting/running it here: https://repl.it/languages/javascript

You should be able to see that there is clearly a problem with the suggested "between" code.

Ask questions.


#6

A post was split to a new topic: Everytime the bot chooses rock


#8

Neither do you get taught from the basic if/else script that you don't need to use return or log in the brackets but you can just call in the middle of a statement. It is confusing to know you can do things in a shorter way without being taught. Seeing it here, it is much easier than I was making it!


#9

Could you tell us more about what you mean by this?


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.