Wednesday, March 20, 2013

Codecademy

For my group tutorials I've been teaching myself JavaScript at Codecademy so I can hopefully end up helping program the game if I actually get good enough to be able to program advanced game-type stuff. I've pretty much just been doing the tutorials for JavaScript on the website. They're not too hard, you just have to think about what you're doing. Below is a sample of a code I did in one of the tutorials to make a rock paper scissors game. Anyway, hopefully I'll keep learning JavaScript and be able to help with the programming eventually!


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}

while(userChoice!=="rock" && userChoice!=="paper" && userChoice!=="scissors"){
userChoice = prompt("Please choose again.");
}

var compare = function(choice1,choice2){
if(choice1===choice2){
return "The result is a tie!"};
if(choice1==="rock"){
if(choice2==="scissors"){
return "rock wins";
} else {
return "paper wins";
}
};
if(choice1==="paper"){
if(choice2==="rock"){
return "paper wins";
}
else {
return "scissors wins";
}
}
if(choice1==="scissors")
if(choice2==="rock"){
return "rock wins";}
else{
return "scissors wins";
}
};

compare(userChoice,computerChoice)


No comments:

Post a Comment