ARRAY 2 DIMENSI
Assalamu’alaikum
Wr.Wb
Kali ini kita
akan membahas ARRAY 2 DIMENSI.
Langsung saja :
*cara menulis indeks array 2 dimensi :
Nama array [indeks baris,indeks
kolom]
*untuk mengisikan :
Identifikasi array : data
*untuk mengambil :
Variabel = identitas array
70 = Y [1,2]
*JAWAB :
*JAWAB :
2. X[0,2] ke Y[0,1]
5. X[1,0] ke Y[2,2]
<html> | |
<head> | |
<title>Test Array 2 Dimensi Dinamis</title> | |
<style> | |
label | |
{ | |
width : 100px; | |
padding:7px; | |
display: inline-block; | |
color: black; | |
} | |
</style> | |
<script type="text/javascript"> | |
var b=0; | |
var DataBarang = new Array(); | |
var kodebar; | |
var a; | |
function _DaftarHarga(DataBarang) | |
{ | |
var harga; | |
if(DataBarang == "Gula Putih") | |
{ | |
harga = 11000; | |
} | |
else if(DataBarang == "Susu Kaleng") | |
{ | |
harga = 5500; | |
} | |
else if(DataBarang == "Minyak Goreng") | |
{ | |
harga = 7300; | |
} | |
else if(DataBarang == "Beras") | |
{ | |
harga = 9800; | |
} | |
else if(DataBarang == "Sarden") | |
{ | |
harga = 8500; | |
} | |
return harga; | |
} | |
function penjumlah() | |
{ | |
var harga = parseInt(document.getElementById("txtHarga").value); | |
var jumlah = document.getElementById("txtJumlah").value; | |
var a; | |
i = parseInt(harga * jumlah); | |
document.getElementById("txtJum").innerHTML = i; | |
return i; | |
} | |
function InputData() | |
{ | |
DataBarang[b] = new Array(); | |
DataBarang[b][0] = document.getElementById("txtKode").value; | |
DataBarang[b][1] = document.getElementById("txtBarang").value; | |
DataBarang[b][2] = document.getElementById("txtJumlah").value; | |
DataBarang[b][3] = penjumlah(); | |
b++; | |
document.getElementById("txtBarang").value=""; | |
document.getElementById("txtKode").value=""; | |
document.getElementById("txtJumlah").value=""; | |
document.getElementById("txtJum").value=""; | |
} | |
//KURANG TOTAL HARGA DAN JUMLAH YANG DI INGINKAN | |
function HitungTotal() | |
{ | |
var total = 0; | |
document.getElementById("txtHasil").innerHTML=""; | |
for(var s=0; s<DataBarang.length;s++){ | |
document.getElementById("txtHasil").innerHTML += DataBarang[s][0]+"="+DataBarang[s][1]+"="+DataBarang[s][2]+"="+DataBarang[s][3]+"<br>"; | |
total +=DataBarang[s][3]; | |
} | |
document.getElementById("txtTotal").innerHTML=total; | |
} | |
</script> | |
</head> | |
<script> | |
//function input | |
function DaftarHarga() | |
{ | |
var DataBarang = document.getElementById("txtBarang").value; | |
var harga = _DaftarHarga(DataBarang); | |
document.getElementById("txtHarga").value = harga; | |
} | |
</script> | |
<body> | |
<body style="background-color : pink"> | |
<div class="tengah"> | |
<h2 style="border : 2px solid white; width : 25%;color:white;background-color:black">Sistem Penjualan Toko </h2> | |
<label style="color : black">Kode Barang : </label> | |
<select id="txtKode" name="Kode List"> | |
<option value="K001">K001</option> | |
<option value="K002">K002</option> | |
<option value="K003">K003</option> | |
<option value="K004">K004</option> | |
<option value="K005">K005</option> | |
</select><br> | |
<label style="color : black">Nama Produk : </label> | |
<select id="txtBarang" name="Barang List" onchange="DaftarHarga()"> | |
<option value="Gula Putih">Gula Putih</option> | |
<option value="Susu Kaleng">Susu Kaleng</option> | |
<option value="Minyak Goreng">Minyak Goreng</option> | |
<option value="Beras">Beras</option> | |
<option value="Sarden">Sarden</option> | |
</select><br> | |
<label style="color : black">Harga : </label> | |
<input type="text" id="txtHarga" disabled/><br> | |
<label style="color : black">Jumlah :</label> | |
<input type="text" id="txtJumlah"/><br> | |
<input style="border :2% solid white; width :10%;color :white;background-color:black" type="button" value="Tambah Produk" onclick="InputData();"> | |
<input style="border :2% solid white; width :10%;color :white;background-color:black" type="button" value="Hitung Total" onclick="HitungTotal();"><br> | |
<label id="txtHasil"></label> | |
<label id="txtJum"></label> | |
<label id="txtTotal"></label> | |
</body> | |
</html>Sistem Penjualan Toko |
Demikian
pembahasab ARRAY 2 DIMENSI coy , jika ada saran bisa di tulis di kolom komentar
di bawah. !!!
Wassalam Wr.Wb
Tidak ada komentar:
Posting Komentar