Rock Paper Scissors !

Are you up for a battle ?

by Uzair Mehmood

HTML

<h1 class="head">Rock Paper Scissors</h1>

<div class="main">
    <p id="message">Game Ready !</p>
    <button id="Rock">Rock</button>
    <button id="Paper">Paper</button>
    <button id="Scissor">Scissor</button>
</div>
<div>
    <p class="score">Score : <span id="score">0</span></p>
    <span class="cheat">psst, click here to always win</span>
</div>

CSS

.main {
    width: 100%;
    text-align: center;
}
.score {
    color:Indigo;
}
.cheat {
    float:right;
    font-size:xx-small;
    color:lightpink;
}
#message {
    color:LightCoral;
}
body{
    background:Linen;
}
p {
    text-align:center;
    font-size:large;
}
h1 {
    color:Indigo;
    text-align:center;
}
button {
    border:none;
    color:white;
    background:LightCoral;
    font-size:large;
    display: inline-block;
}

JavaScript

var options = ["Rock", "Paper", "Scissor"];
var score = 0;
var cheat = false;

$("button").click(function () {
    var Player = $(this).attr('id');
    if (cheat) {
        var Me = looseTo(Player);
    }else{
    var Me = options[Math.floor(Math.random() * options.length)];
    }
    var winner = whoWon(Me, Player);
    if (winner == 'You') {
        refreshScore();
    }
    $('#message').html('I chose ' + Me + '<br />' + winner + ' Won !');
});

function whoWon(a, b) {
    var winner = 'I';
    if (a == b) {
        winner = 'No one';
    } else {
        switch (a) {
            case 'Rock':
                if (b == 'Paper') {
                    winner = 'You';
                }
                break;
            case 'Paper':
                if (b == 'Scissor') {
                    winner = 'You';
                }
                break;
            case 'Scissor':
                if (b == 'Rock') {
                    winner = 'You';
                }
                break;
        }
    }
    return winner;
}

function looseTo(option){
    var Me = '';
    switch (option) {
        case 'Rock':
            Me = 'Scissor';
            break;
        case 'Paper':
            Me = 'Rock';
            break;
        case 'Scissor':
            Me = 'Paper';
            break;
    }
    return Me;
}

function refreshScore() {
    score++;
    $('#score').text(score);
}

$('.cheat').click(function(){
    if(cheat){
        cheat = false;
        $(this).text('psst, click here to always win');
    }else{
        $(this).text('click again to revert');
        cheat = true;
    }
});