JavaScript学习笔记

个人工作室:www.rswebun.com

不会JavaScript的前端工程师只会沦为前端美工…所以,努力!!
正在学习JavaScriptCodeCademy这是个很棒的在线学习网站,讲解详细,非常适合入门~

mark一下第一个自己写的函数,Rock, Paper, Scissors!

 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var rockPaperScissors = function(a,b){
    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";
    }
    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(choice1==="scissors"){
            if(choice2==="rock"){
                return "rock wins";
            }else{
                return "scissors wins";
            }
        }else{
            return "Opps!";
        }
    };
    compare(userChoice,computerChoice);
};
rockPaperScissors();
posted @ 2013-06-25 15:21  五叶神  阅读(90)  评论(0编辑  收藏  举报