Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var click = document.querySelector( "button" );
- click.addEventListenet( "click", function() {
- // Ambil semua input
- var inputs = document.querySelectorAll( "input" );
- // Nilai pada input Rp 500
- var jumlah500 = inputs[0] ? inputs[0] : 0,
- total500 = jumlah500 * 500;
- // Nilai pada input Rp 1000
- var jumlah1000 = inputs[1] ? inputs[1] : 0,
- total1000 = jumlah1000 * 1000;
- // Nilai pada input Rp 1500
- var jumlah1500 = inputs[2] ? inputs[2] : 0,
- total1500 = jumlah1500 * 1500;
- // Nilai pada input Rp 2000
- var jumlah2000 = inputs[3] ? inputs[3] : 0,
- total2000 = jumlah2000 * 2000;
- var jumlahKertas = jumlah500 + jumlah1000 + jumlah1500 + jumlah2000,
- totalHarga = total500 + total1000 + total1500 + total2000;
- console.log( "Jumlah kertas: " + jumlahKertas );
- console.log( "Total Harga: " + totalHarga );
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement