₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,329,655 members, 8,441,697 topics. Date: Wednesday, 08 July 2026 at 10:56 PM

Toggle theme

Rock Paper And Scissors Game In - Javascript - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingRock Paper And Scissors Game In - Javascript (1766 Views)

1 Reply

Rock Paper And Scissors Game In - Javascript by losprince(op): 2:11am On Nov 22, 2014
so i decided to get serious in javascript, and thought i should do a rock paper and scissor game.

features:
lets the user input how many times they want to play
checks for invalid inputs
displays the final scores
the computer is just random

so here it is... of course in .html format. copy, paste and run in your browser

<html>
<head>
<title>rock , paper, scissors</title>
</head>
<body>
<script type="text/javascript">

var numOfgames = prompt("how many times would you like to fight?"wink;
parseInt(numOfgames);
gameCount=0;//this would be used to determine the end value

var win=0;
var loss=0;
var draw=0;//this three variables will hold the final scores
while(gameCount<numOfgames)
{

var playerChoice = prompt("what weapon would you like to attack the computer with: paper, rock, or scissors?"wink;
var choiceList = new Array("","rock", "paper", "scissors"wink;//an array that holds strings the computer can randomly select

var computerChoice=choiceList[Math.ceil(Math.random()*3)];//a statement that makes the computer select randomly from the array

if (playerChoice == computerChoice){
alert(playerChoice + " Against " + computerChoice + " its a Draw!"wink;
draw++;//increases the draw score line
}
else if(playerChoice == "rock"wink {
if (computerChoice == "scissors"wink{
alert("rock crushes scissors!! player WINS!"wink;
win++;//increases the win score line
}else if (computerChoice == "paper"wink
{
alert("paper cover rock... computer WINS!" );
loss++;//increases the loss score line
}
}else if(playerChoice == "paper"wink{
if (computerChoice == "rock"wink{
alert("paper covers rock... player WINS!"wink;
win++;
}else if(computerChoice == "scissors"wink
{
alert("scissors cuts papers! computer WINS!"wink;
loss++;
}
}else if(playerChoice == "scissors"wink{
if (computerChoice == "paper"wink{
alert("scissors cuts paper! player WINS!"wink;
win++;
}else if(computerChoice == "rock"wink
{
alert("rock crushes scissors!! computer wins!"wink;
loss++;
}
}else{
alert("please choose a valid weapon to fight the computer with; from \"rock, paper, scissors\""wink;
continue;//continue looping without affecting the program flow
}//end if
gameCount++;
alert(numOfgames-gameCount + " more fights left!"wink;
//document.write("<pre>"+"wins:"+win +" loss:"+loss +" draw:"+draw +"</pre><br />"wink;//uncomment this if you want to see your score after each fight
}
document.write("<pre>"+"wins:"+win +" loss:"+loss +" draw:"+draw +"</pre><br />"wink;//displays the scores in a html format
</script>

</body>
</html>

thanks for even opening this thread cool better programs ahead
Re: Rock Paper And Scissors Game In - Javascript by losprince(op): 2:19am On Nov 22, 2014
please replace the wink with ) "thats paranthesis"
Re: Rock Paper And Scissors Game In - Javascript by losprince(op): 9:58am On Nov 22, 2014
programmers this silence is not encouraging o... pls say something.
1 Reply

Functional Programming In JavascriptPattern Chaser In Javascript: Coding ChallengeCookie Programming In Javascript234

C++ Gurus Get In Here Lets Dissect C++. C++ A_z Tutorials.Please Does Any One Know Aw To Create A School Portal With Word Press Or JoomlaWhich Website Do You Download Your Ebooks From ?