-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample6-answer.html
42 lines (39 loc) · 1.19 KB
/
sample6-answer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8"/>
<title>Sample Page 6(練習問題)</title>
<script type="text/javascript">
// array に入っている値で"*"を使った棒グラフを表示したい。
// プログラムの ____ 部分にふさわしい命令を考えよう
// str を n 回繰り返した文字を作る関数
function strtimes( str , n ) {
let ans = "" ;
for( let i = 1 ; i <= n ; i++ )
ans += str ;
return ans ;
}
function main() {
// グラフにしたいデータ
let array = [ 1 , 3 , 5 , 9 , 10 , 6 , 3 , 2 ] ; /* 配列 */
// 配列全部を順次棒グラフにする。
let out = "" ;
for( let n of array ) {
out += n + " : " + strtimes( "*" , n ) + "<br/>" ;
// ("00"+n).slice(-2) を使うと、数字の前に0を埋めて2桁表示にしてくれる。
}
document.getElementById( "output" ).innerHTML
= out ;
}
</script>
</head>
<body onload="main()">
<h1>Sample Page 6(練習問題)</h1>
<h2>棒グラフ</h2>
<div id="output"></div>
</body>
</html>
<!-- Local Variables: -->
<!-- mode: html -->
<!-- tab-width: 8 -->
<!-- End: -->