1 / 22

Pemrograman Javascript

Pemrograman Javascript. Teknik Informatika Universitas Bunda Mulia Jakarta Chandra Hermawan H., M.Kom ., MM. Mengenal Fungsi Pada Javascript. Function dideklarasikan menggunakan reserved word function. Contoh : function factorial(n) { if (n <=0) { return(1); } else {

jess
Download Presentation

Pemrograman Javascript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PemrogramanJavascript TeknikInformatika Universitas Bunda Mulia Jakarta Chandra Hermawan H., M.Kom., MM.

  2. MengenalFungsiPadaJavascript Function dideklarasikanmenggunakan reserved word function. Contoh: function factorial(n) { if (n <=0) { return(1); } else { return(n * factorial(n-1)); } }

  3. VariabelLokal & Global • JikaPendeklarasianvaribeltanpamenggunakan kata kuncivar (biasadisebutcaraimplisit) makavariabeltersebutdapatdiaksesdariseluruhbagian program. Dengankata lain semuafungsi yang adadalam program dapatmemanggildanmemakaivariabelini. Hal sepertiiniseringdisebutsebagaivariabel Global • Sebaliknyajikapendeklarasianvariabelmenggunakan kata kuncivar (eksplisit), sertapengaksesanvariabeltersebuthanyadalamlokasitertentudimanavariabeltersebutdideklarasikan, makavariabelsepertiinibiasadisebutvariabelLocal.

  4. ContohVariabelLokal : <html> <head><title>penulisanvariabel</title></head> <body> < script language=“JavaScript” > <!— var a=67; var b=88; function perkalianDengan2(b){ var a=b*2; Return a; } document.write(“dua kali dari“,b,”adalah”,perkalianDengan2(b)); document.write(“Nilaidari a adalah“,a); //--> </script> </body></html>

  5. ContohVariabel Global : <html> <head><title>penulisanvariabel</title></head> <body> < script language=“JavaScript” > <!— var a=67; var b=88; function perkalianDengan2(b){ a=b*2; return a; } document.write(“dua kali dari“,b,”adalah”,perkalianDengan2(b)); document.write(“Nilaidari a adalah“,a); //--> </script> </body></html>

  6. PengembalianNilai • Dapatmengembalikannilaiatautidak, bentukpenulisannya: • returnexpression; • Dapatjugasepertiini : • return;

  7. String

  8. Date & Time

  9. Date & Time (2)

  10. Array • Masing-masing element diwakiliolehnomorurut • Dimulaidengannomorurut 0 • Disebutsebagai index • Cara akses • Nama array • Brackets • Nomorurut element • Mengetahuipanjang array • length

  11. Contoh Array = c[ 0 ] -45 Namaarray = c[ 1 ] 6 = c[ 2 ] 0 = c[ 3 ] 72 = c[ 4 ] 1543 = c[ 5 ] -89 = c[ 6 ] 0 = c[ 7 ] 62 = c[ 8 ] -3 = c[ 9 ] 1 = c[ 10 ] 6453 = c[ 11 ] 78 Nomorurut / index

  12. Deklarasi var c;c = new Array( 12 ); atau var c = new Array( 12 );

  13. The for loop sums the values contained in the 10-element integer array called theArray. SumArray.html(1 of 2) Variable element is assigned a subscript in the range of 0 up to, but not including, theArray.length.

  14. MetodePada Array • Array Join: • Menggabungkanisidari array menjadi 1 baris string • Dapatditentukankarakterpemisahnya • Contoh : nama_array.join (“ “); • Array Reverse: • Membalikurutanelemen array, yang terakhirmenjadi yang pertama, atausebaliknya. • Contoh: nama_array.reverse(); • Array Sort: • Untukmengurutkan array berdasarkankode ASCII • Contoh: nama_array.sort();

  15. Array 2 Dimensi Column 0 Column 1 Column 2 Column 3 a[ 0 ][ 0 ] a[ 0 ][ 1 ] a[ 0 ][ 2 ] a[ 0 ][ 3 ] Row 0 a[ 1 ][ 0 ] a[ 1 ][ 1 ] a[ 1 ][ 2 ] a[ 1 ][ 3 ] Row 1 a[ 2 ][ 0 ] a[ 2 ][ 1 ] a[ 2 ][ 2 ] a[ 2 ][ 3 ] Row 2 Column subscript (or index) Row subscript (or index) Array name

  16. Pendeklarasian Array 2 Dimensi var b = [ [ 1, 2 ], [ 3, 4, 5 ] ]; Atau var b; b = new Array( 2 ); b[ 0 ] = new Array( 5 ); b[ 1 ] = new Array( 3 );

  17. Arrayarray1 provides six initializers in two rows. Arrayarray2 provides six initializers in three rows. Function outputArray displays each array’s elements in a Web page. InitArray3.html(1 of 2)

  18. Referencing the multidimensional array theArray. InitArray3.html(2 of 2)

  19. Latihan • Buatlahsebuah Quiz Online menggunakan Form dan Array

  20. THANK YOU

More Related