JavaScript おみくじ

<!DOCTYPE>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>おみくじ</title>
<style>
body {
background: #e0e0e0;
text-align: center;
font-size: 16px;
color: #fff;
font-family: Arial, sans-serif;
}

#result {
margin: 30px auto;
width: 180px;
height: 180px;
border-radius: 50%;
line-height: 180px;
font-size: 48px;
font-weight: bold;
background: #f44336;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
#btn {
margin: 0 auto;
width: 200px;
padding: 5px;
border-radius: 5px;
background: #00aaff;
box-shadow: 0 4px 0 #0088cc;
cursor: pointer;
}
#btn:hover {
opacity: 0.8;
}

#btn.pushed {
margin-top: 32px;
box-shadow: 0 2px #0088cc;
}
</style>
</head>

<body>
<div id="result">?</div>
<div id="btn">あなたの運勢は?</div>

<script>
(function(){
"use strict"

document.getElementById('btn').addEventListener('click',function(){
var results = ['大吉','中吉','小吉','凶'];
// 0 - n
// Math.floor(Math.random() * (n + 1))
// Math.floor 0 - 0.9999.... の乱数を作る
// Math.floor(Math.random() * 4) 0 - 3.99999 切りすて 0 - 3の乱数ができる
var result = Math.floor(Math.random() * results.length);
document.getElementById('result').innerHTML = results[result];
});
// マウスを乗せた時の処理
document.getElementById('btn').addEventListener('mousedown', function(){
this.className = 'pushed';
});
// マウスを外した時の処理
document.getElementById('btn').addEventListener('mouseup', function(){
this.className = '';
});

})();
</script>
</body>
</html>