JavaScript 3-2 配列

実践課題B
<script>
var product=['リラックスチェア','リラックスデスクブック','スタンド'];
var price=[4000,12000,800];

document.write('<tr>');
document.write('<td>'+product[0]+'<\/td>');
document.write('<td>'+price[0]+'円<\/td>');
document.write('<\/tr>');

document.write('<tr>');
document.write('<td>'+product[1]+'<\/td>');
document.write('<td>'+price[1]+'円<\/td>');
document.write('<\/tr>');

document.write('<tr>');
document.write('<td>'+product[2]+'<\/td>');
document.write('<td>'+price[2]+'円<\/td>');
document.write('<\/tr>');

</script>
</table>

実践課題B-2
table border="1">
<tr><th>製品名</th> <th>価格</th></tr>

<script>
var product=['リラックスチェア','リラックスデスクブック','スタンド'];
var price=[4000,12000,800];

for(var i=0; i<3; i++){
document.write('<tr>');
document.write('<td>'+product[i]+'<\/td>');
document.write('<td>'+price[i]+'円<\/td>');
document.write('<\/tr>');
}

</script>
</table>

実践課題C
<script>

var lk=['ホーム','会社情報','製品情報','お問い合わせ'];

for(var i=0; 0<lk.length; i++){
	document.write('<ul>');
	document.write('<li><a href="#">'+lk[i]+'</a><\/li>');
	document.write('<\/ul>');	
}
</script>

実践課題D
<table border="1">
<tr><th>添字</th> <th>a</th> <th>b</th> <th>a*bを計算</th></tr>
<tr><th>0</th> <th>5</th> <th>33</th> <th><button onClick="kakezan(0)">計算結果</button></th></tr>
<tr><th>1</th> <th>12</th> <th>14</th> <th><button onClick="kakezan(1)">計算結果</button></th></tr>
<tr><th>2</th> <th>18</th> <th>65</th> <th><button onClick="kakezan(2)">計算結果</button></th></tr>

<script>

var num1=[5,12,18];
var num2=[33,14,65];
var ans;
num1[0]=5;

function kakezan(i){
	ans=num1[i]*num2[i];
	alert('答えは'+ans+'です');
	
}
</script>
</table>

実践課題E
<table border="1">
<tr><th>個数</th> <th>商品A</th> <th>商品B</th> <th>商品C</th></tr>


<script>
var price=[300,450,520];

for(var i=1; i<=10; i++){
	document.write('<tr>');
	document.write('<th>'+i+'<\/th>');
	for(var j=0; j<3; j++){
		document.write('<td>'+price[j]*i+'円<\/td>');
	}
		document.write('<\/tr>');	
}
</script>
</table>