Wednesday, February 13, 2013

Coding Tutorials

I've been learning Javascript on Codecademy. In the current tutorial I'm doing, I am making a simple rock paper scissors game involving a ton of If/else if/else statements and I've also learned how to make variables and functions. This website is so fun and I'm learning a ton of stuff about coding. Now when making our game I can kind of understand what is going on with coding.

http://www.codecademy.com/tracks/javascript


var userChoice = prompt("Do you choose rock, paper, or scissors?");
var computerChoice = Math.random();

if (computerChoice <= 0.33)
{
computerChoice = "rock";
}
else if (0.34 < computerChoice && computerChoice <=0.66)
{
computerChoice = "paper";
}
else 
{
computerChoice = "scissors";
}
console.log(computerChoice);


Here is a part of the code for the game, and basically the computer pick a random number between 0 and 1, and then I made a statement so that if the code is between a certain range, it will pick either rock, paper, or scissors. And it also prompts the user on what they pick.

No comments:

Post a Comment