先ほどは使い慣れていないのもあり雑な質問の仕方をしてしまいすいません。
以下javaの二重丸のところの指示を書き足して、「サイコロを振る」のボタンを押すと、このように
つらつらと数字が出てくる動作を実行したいです。
html
1<!doctype html> 2<html> 3<head> 4<meta charset="UTF-8"> 5<title>無題ドキュメント</title> 6<link rel="stylesheet" href="style.css"> 7</head> 8 9<body> 10 11<div id="history"></div> 12<dl id="stats"> 13 <dt>1</dt> 14 <dd></dd> 15 <dt>2</dt> 16 <dd></dd> 17 <dt>3</dt> 18 <dd></dd> 19 <dt>4</dt> 20 <dd></dd> 21 <dt>5</dt> 22 <dd></dd> 23 <dt>6</dt> 24 <dd></dd> 25</dl> 26<button id="dice">サイコロを振る</button> 27<button id="sort">並び替え</button> 28<script src="javascript.js"></script> 29</body> 30</html>
css
1 2 3@charset "UTF-8"; 4/* CSS Document */ 5body{ 6 text-align: center; 7 padding: 40px; 8} 9 10#history{ 11 border: 4px solid #33AA66; 12 margin: 40px auto; 13 min-height: 1em; 14 padding: 20px; 15 color: #33AA66; 16 font-size: 24px; 17 line-height: 1; 18} 19dl#stats{ 20 margin: 40px auto; 21 color: #33AA66; 22 font-weight: bold; 23 text-align: center; 24} 25dl#stats dt, dl#stats dd{ 26 display:inline; 27 margin: 0; 28 padding: 0; 29 font-size: 16px; 30 font-weight: normal; 31 32} 33dl#stats df:after { 34 content:":"; 35} 36dl#stats dd { 37 margin-right: 10px; 38 font-weight: bold; 39 color: #0066FF; 40} 41button{ 42 background-color: #33AA66; 43 border: none; 44 display: inline-block; 45 padding: 16px 32px; 46 color: #FFFFFF; 47 font-size: 16px; 48 text-align: center; 49 text-decoration: none; 50 51}
java
1// JavaScript Document 2 3//変数 dice :ボタン 4var dice = document.getElementById('dice'); 5//変数 dice :ボタン 6var sort = document.getElementById('sort'); 7//変数 dicehistory :履歴。idがhistoryの要素を取得 8var diceHistory= document.getElementById('history'); 9//◎変数 stats : HTML要素 stats を取得 10 11//◎変数 statsItems :上記 stats 中のdd要素をすべて取得 12 13//変数 numbers: 出た数字を入れる配列 14var numbers= []; 15//◎変数 counts カウントした各数を入れる配列 16 17dice.addEventListner('click',diceClickHandler); 18//◎sortボタンを押した時に関数sortClickHandlerを実行 19 20function diceClickHandler(){ 21 //サイコロを振る(ランダム) 22 var num = Math.floor(Math.random() * 6 + 1); 23 numbers.push(num); 24 //◎配列countsの該当する要素を1加算する 25 26 updateDiceHistory(); 27} 28function updateDiceHistory(){ 29 //履歴表示をアップデート 30 diceHistory.innerHTML = numbers.join(' _ '); 31 dicplayCount(); 32} 33function displayCount(){ 34 //◎繰り返し処理を使って、counts の各項目を statsItemsの各dd要素に表示 35} 36 37
回答2件
あなたの回答
tips
プレビュー