Rock, Paper, Scissors game in JavaScript I built this as part of completing the Codecademy JavaScript lesson. I wanted to perfect it, make it readable and functional, and as efficient as possible. As far as I can tell it can't be any more efficient than this. But maybe I can't tell. What do you think? I know there are little things, maybe the victory variable should have a console.log in it. Probably one or two more. But hopefully this is a good example for people who need help with writing their Rock, Paper, Scissors challenge.

//Loop ensures only valid user input is rock, paper, scissors
var i, infiniteloop;
for (i=0; i&lt;1; infiniteloop++) //infiniteloop allows loop to continue if user is infinitely retarded
{
    var userChoice = prompt("You're playing rock, paper, scissors against the computer. Type your choice in lower case letters.")
    if (userChoice === "rock") {i=1;} //escapes loop
        else if (userChoice === "paper") {i=1;} //escapes loop
        else if (userChoice === "scissors") {i=1;} //escapes loop
        else {alert("Try again, stupid.");} //alerts, loops back to start
}

console.log("You chose " + userChoice + "!"); //announces userChoice

//generate a random computer choice, assign a string to replace it
var computerChoice = Math.random(); //random function. generates a number between 0 and 1
if (computerChoice &lt;= .33) { computerChoice = "rock"; }
    else if (computerChoice &lt;= .66) { computerChoice = "paper"; }
    else { computerChoice = "scissors"; }

console.log("Computer chose " + computerChoice + "!"); //announces computerChoice

var victory = "You win! A master strategist is you." //preset victory announcement
if (userChoice === computerChoice) { console.log("Tie game!"); }
    else if (userChoice === "rock" &amp;&amp; computerChoice === "scissors") { victory }
    else if (userChoice === "paper" &amp;&amp; computerChoice === "rock") { victory }
    else if (userChoice === "scissors" &amp;&amp; computerChoice === "paper") { victory }
    else {console.log("You have suffered a devastating loss.");}
Here are my 2 cents to improve your code. 

First of all, if you're going to be using an infinite loop anyways to check for user input, why not make it a while loop instead of a for loop? 

while (i === 0)
{
    var userChoice = prompt("You're playing rock, paper, scissors against the computer. Type your choice in lower case letters.")
    if (userChoice === "rock") {i=1;} //escapes loop
        else if (userChoice === "paper") {i=1;} //escapes loop
        else if (userChoice === "scissors") {i=1;} //escapes loop
        else {alert("Try again, stupid.");} //alerts, loops back to start
}


I personally feel that a while loop is far easier to read than a for loop, and in your case you have two variables which doesn't seem necessary. By using a while loop, you won't need to have the 'infiniteloop' variable.

Also, it looks like the victory messages won't be printed to the console as you're just calling the strings after each case. 
This should do the trick:

else if (...) { console.log(victory); }


Congrats on finishing a game though! It's always a great place to start :)

Best of luck for your coding journey!!

shifubear