Wednesday, February 19, 2014

rock paper scissors

var userChoice = prompt("Do you choose rock, paper or scissors?"); if (userChoice!="rock" && userChoice!="paper" && userChoice!="scissors") { userChoice = prompt("please enter a valid choice"); }; var computerChoice = Math.random(); if (computerChoice < 0.34) { computerChoice = "rock"; } else if(computerChoice <= 0.67) { computerChoice = "paper"; } else { computerChoice = "scissors"; } var compare=function(choice1, choice2) { if (choice1===choice2) { return"The result is a tie!"; } else if(choice1==="rock") { if (choice2==="scissors") { return "rock wins"; } else { return "paper wins"; } } else if(choice1==="paper") { if(choice2==="rock") { return "paper wins"; } else { return "scissors wins"; } } else { if(choice2==="rock") { return "rock wins"; } else { return "scissors wins"; } } }; console.log(compare(userChoice, computerChoice)); Play Game!

Tuesday, February 18, 2014

function definition
JS creates functions by assigning variables to them, instead of defining new commands like Python
function syntax
var name=function(param){what the function does;};
parameters
stuff in parentheses when function is defined
arguments
stuff in parentheses when function is called
call
to execute the commands in a function
D.R.Y.
don't repeat yourself
return
saves but does not print the result of the function
scope
global or local
global
defined outside a function
local
defined inside a function and only applicable in that particular function
var
used to define the scope of a variable, can be used even on variables of the same name to leave a global variable unchanged

Tuesday, February 11, 2014

Hello World

I made a Hello World js program.

console.log("Hello World");

Saturday, February 8, 2014

shapes notes

  • graphics in order of first on the bottom
  • y coordinate reversed
  • default fill=black if none listed
my svg graphic

Tuesday, February 4, 2014

batman

var age=prompt("What's your age?"); if(age<18) { console.log("you may play but I am not responsible for anything"); } else { console.log("play on!"); } console.log("Snow White and Batman were hanging out at the bus stop, waiting to go to the shops. There was a sale on and both needed some new threads. You've never really liked Batman. You walk up to him."); console.log("Batman glares at you."); var userAnswer=prompt("Are you feeling lucky.punk?"); if(userAnswer==="yes") { console.log("Batman hits you very hard. It's Batman and you're you! Of course Batman wins!"); } else { console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by batman."); } var feedback=prompt("rate this game out of ten"); if(feedback>8) { console.log("This is just the begining of my game empire. Stay tuned for more!"); } else { console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!"); }