My "Rock Paper Scissors" assignment asked for me to use very specific diameters too. It has simply not been working. Instead of any of the logged consoles coming up, the page won't even load.
I originally had all of the strings in the console as alerts that would pop up on the page, but that didn't work so I just switched it to console hoping it would pop up if I used node, but that also didn't work. I moved around the player and computer wins, in and out of the functions to see if that would change anything, but it didn't.
var hands = ['Rock', 'Paper', 'Scissors'];
function getHand(){
return hands[parseInt(Math.random()*hands.length)%3];
}
var player1 = "Mike";
console.log("Hello " + player1);
var player2;
console.log("Player 2 is the computer!");
//var playWins = 0;
//var compWins = 0;
function playRound(){
if (hand == computer){
console.log("You guys tied!");
} else if (hand == "Scissors" && computer == "Rock"){
console.log(player1 + " has lost! Sadddd...");
compWins++;
} else if (hand == "Paper" && computer == "Rock"){
console.log(player1 + " has wonnnn!!! Yay! I guess...");
playWins++
} else if (hand == "Rock" && computer == "Scissors"){
console.log(player1 + " has wonnnn!!! Yay! I guess...");
playWins++;
} else if (hand == "Paper" && computer == "Scissors"){
console.log(player1 + + " has lost! Sadddd...");
compWins++;
} else if (hand == "Rock" && computer == "Paper"){
console.log(player1 + + " has lost! Sadddd...");
compWins++;
} else if (hand == "Paper" && computer == "Paper"){
console.log(player1 + " has wonnnn!!! Yay! I guess...");
playWins++;
} else {console.log("There seems to be a problem.");}
}
hand = [];
computer = [];
while (hand <= 3 || computer <= 3){
for (i = 0; i >=5; i++ ){
hand.push(getHand());
computer.push(getHand());
playRound();
}
}
if(playWins>compWins){
console.log(player1 + " Wins!");
} else {
console.log("Computer Wins!");
}
I expected it to tell me who wins each game, then who wins altogether after at least 5 matches. I can't see my error messages because the page won't even fully load.
You have an infinite loop. A couple errors are making that happen. First, these are arrays:
while (hand <= 3 || computer <= 3)
So I'm guessing you want to check their length?:
while (hand.length <= 3 || computer.length <= 3)
Then you also have a logical error here:
for (i = 0; i >=5; i++ ){
Since i
starts as 0
, it is immediately not >= 5
, so the for
loop is never entered and the while
loop just repeats indefinitely. You probably want <=
:
for (i = 0; i <= 5; i++ ){
You'll also want to uncomment these so the variables are defined, since you use those variables later:
var playWins = 0;
var compWins = 0;