JavaScript Source Code 3000: Games: Rock, Paper, Scissors
Rock, Paper, Scissors
Play Rock, Paper, Scissors against your computer. Make your selection and the computer will randomly choose as well and then the game will be scored. Fun!
JavaScript Source Code 3000: Games: Rock, Paper, Scissors Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!
<!-- THREE STEPS TO INSTALL ROCK, PAPER, SCISSORS:
1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document 3. Also be sure to save the game images to your server -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript"> <!-- Suggestion by: mi-cul@boya-kasha.co.uk --> <!-- Based on code by: Maximilian Stocker (maxstocker@reallyusefulcomputing.com) -->
<!-- Original: Ronnie T. Moore --> <!-- Web Site: JavaScript Source Code 3000 -->
<! > <! >
<!-- Begin function playGame(choice) { with (document.game) { comp = Math.round((Math.random() * 2) + 1); var choicename; if (comp == 1) choicename = "rock"; if (comp == 2) choicename = "paper"; if (comp == 3) choicename = "scissors"; msg.value = 'The computer chose ' + choicename + '; ';
switch(choice) { // calculates score case 1 : // rock if (comp == 1) { draw.value++; msg.value += 'It is a draw.'; break; } if (comp == 2) { loss.value++; msg.value += 'You lost!'; break; } if (comp == 3) { win.value++; msg.value += 'You won!'; break; } case 2 : // paper if (comp == 1) { win.value++; msg.value += 'You won!'; break; } if (comp == 2) { draw.value++; msg.value += 'It is a draw.'; break; } if (comp == 3) { loss.value++; msg.value += 'You lost!'; break; } case 3 : // scissors if (comp == 1) { loss.value++; msg.value += 'You lost!'; break; } if (comp == 2) { win.value++; msg.value += 'You won!'; break; } if (comp == 3) { draw.value++; msg.value += 'It is a draw.'; break; } } msg.value += ' Go again!'; } } // End --> </script> </HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->