Skip to content

Instantly share code, notes, and snippets.

@omas-public
Created June 11, 2019 12:32
Show Gist options
  • Save omas-public/7b12db061db762efb6c3ae8639ea5743 to your computer and use it in GitHub Desktop.
Save omas-public/7b12db061db762efb6c3ae8639ea5743 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
h1 {
color: black;
font-size: 42px
}
p {
color: red;
font-size: 32px
}
</style>
<script>
const $ = id => document.getElementById(id)
window.addEventListener('load', () => {
$('button').addEventListener('click', main)
}, false)
function main() {
const hand = Math.floor(Math.random() * 3)
const hands = {
'0': {
path:'stone.png'
,message:'あいこ'
},
'1': {
path:'cissor.png'
,message:'負け'
},
'2': {
path:'paper.png'
,message:'勝ち'
},
}
$('player').src = `./image/${hands[hand].path}`
$('message').innerText = hands[hand].message
}
</script>
<h1>じゃんけんゲーム(相手はグー)</h1>
<div id="image">
<img src="./image/stone.png" alt="dummy" id="computer">
<img src="./image/stone.png" alt="dummy" id="player">
</div>
<button id="button">Game Start</button>
<div id="message"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment