Advertisement
Guest User

kalkulasi kertas

a guest
Jul 16th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var click = document.querySelector( "button" );
  2. click.addEventListenet( "click", function() {
  3.     // Ambil semua input
  4.     var inputs = document.querySelectorAll( "input" );
  5.  
  6.     // Nilai pada input Rp 500
  7.     var jumlah500 = inputs[0] ? inputs[0] : 0,
  8.     total500 = jumlah500 * 500;
  9.  
  10.     // Nilai pada input Rp 1000
  11.     var jumlah1000 = inputs[1] ? inputs[1] : 0,
  12.     total1000 = jumlah1000 * 1000;
  13.  
  14.     // Nilai pada input Rp 1500
  15.     var jumlah1500 = inputs[2] ? inputs[2] : 0,
  16.     total1500 = jumlah1500 * 1500;
  17.  
  18.     // Nilai pada input Rp 2000
  19.     var jumlah2000 = inputs[3] ? inputs[3] : 0,
  20.     total2000 = jumlah2000 * 2000;
  21.  
  22.     var jumlahKertas = jumlah500 + jumlah1000 + jumlah1500 + jumlah2000,
  23.     totalHarga = total500 + total1000 + total1500 + total2000;
  24.  
  25.     console.log( "Jumlah kertas: " + jumlahKertas );
  26.     console.log( "Total Harga: " + totalHarga );
  27. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement