<!DOCTYPE html>
<html>
<head>
	<link rel='stylesheet' href='style.css'/>
	<script src='https://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.7.1/coffee-script.min.js'></script>
	<script src='script.js'></script>
</head>
<body>
<p id="gametext">Let's play Rock-Paper-Scissors!</p>
<p id="result"></p></p>
</body>
 </html>
# RPS in Coffeescript

# var userChoice = "Do you choose rock, paper or scissors?"
var userChoice = "rock"
var computerChoice = Math.random()
console.log computerChoice
if computerChoice < 0.34
    computerChoice = "rock"
else if computerChoice < 0.67
    computerChoice = "paper"
else 
    computerChoice = "scissors"

compare = (choice1, choice2) ->
    if choice1 is choice2 
        outcome = "The result is a tie!"
    
    else if choice1 is "rock"
            if choice2 is "scissors"
                outcome = "rock wins"
            else 
                outcome = "paper wins"
    
    else if choice1 is "paper"
            if choice2 is "rock"
                outcome = "paper wins"
            else 
                outcome = "scissors wins"
    
    else if choice1 is "scissors"
            if choice2 is "rock"
                outcome = "rock wins"
            else 
                outcome = "scissors win"
                
    return outcome

outcome = compare(userChoice, computerChoice)
document.getElementbyId("result").innerHTML = outcome
Created from scratch
0 forks
18 views

Browse more Codebits