Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,161,618 members, 7,847,595 topics. Date: Saturday, 01 June 2024 at 09:46 PM

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

Nairaland Forum / Science/Technology / Programming / Rock Paper And Scissors Game In - Javascript (1527 Views)

Functional Programming In Javascript / Pattern Chaser In Javascript: Coding Challenge / Cookie Programming In Javascript (2) (3) (4)

(1) (Reply)

Rock Paper And Scissors Game In - Javascript by losprince(m): 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(m): 2:19am On Nov 22, 2014
please replace the wink with ) "thats paranthesis"
Re: Rock Paper And Scissors Game In - Javascript by losprince(m): 9:58am On Nov 22, 2014
programmers this silence is not encouraging o... pls say something.

(1) (Reply)

Does Web Development Worth Learning In Nigeria / PDF Expert 2.4.29 Mac Crack / Please How Can I Start Getting Jobs Or Clients As A Website Designer

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 14
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.