Learn JS

Run Settings
LanguageJavascript
Language Version
Run Command
//print console.log("ok google"); //variable type var yourname = 'yukihana'; var number = 12345; var bollean1 = true; var bollean2 = false; var array1 = ['yuki','hana']; var array2 = {'hana':'1','yuki':'2'}; var null_test = null; var nothing; //print variable type console.log(typeof yourname); console.log(typeof number); console.log(typeof bollean1); console.log(typeof bollean2); console.log(typeof array1); console.log(typeof array2); console.log(typeof null_test); console.log(typeof nothing); //constant const PI = 3.14; console.log(PI); //test change value // PI = 1; // console.log(PI); //opperation var day = 31; var month = 8; var year = 7; var total = day + month + year; console.log(day+"-"+month+"-"+year); console.log(total); //assignment opperation var x = 5; var y = 6; console.log("Value : " + x); x += y; // x -= y; // x /= y; // x *= y; // x %= y; console.log("Value after assignment: " + x); var q = 29; var w = 19; console.log( typeof q == w ); console.log( typeof q === w ); console.log( typeof q != w ); console.log( typeof q !== w ); console.log( typeof q > w ); console.log( typeof q < w ); console.log( typeof q >= w ); console.log( typeof q <= w ); var e = 13; var f = 13; var g = 13; var h = 13; ++e; f++; --g; h--; console.log(e); console.log(f); console.log(g); console.log(h); var i = true; var j = true; console.log('x : ' + i + '<br/>'); console.log('y : ' + j + '<br/>'); console.log('!x : ' + !i + '<br/>'); console.log('!y : ' + !j + '<br/>'); console.log('x and y : ' + (i && j) + '<br/>'); console.log('x or y : ' + (i || j) + '<br/>'); console.log('x xor y : ' + Boolean(i ^ j) + '<br/>'); var k = 'yuki'; var l = 'hana'; var m = k + ' ' + l; console.log('k is ' + k); console.log('l is ' + l); console.log('m is ' + m); var master = 'dragneel'; if (master == 're') { message = 'welcome back master'; } else { message = 'go find another maid fucker'; } console.log(message); var panjang = 7; // atau diameter lingkaran var lebar = 3; var tinggi = 0; // tinggi bangun ruang // tinggi = 0; if(tinggi > 0) { console.log('Luas selimut balok: ' + panjang * lebar * tinggi + 'cm'); console.log('Luas selimut tabung: ' + 2 * 3.14 * (panjang/2) * (panjang/2 + tinggi) + 'cm'); } else { console.log('Luas persegi: ' + panjang * lebar + 'cm'); console.log('Luas lingkaran: ' + 0.25 * 3.14 * (panjang*panjang) + 'cm'); } console.log('Nilai: '); var skor = 13; if(skor < 25) { console.log('D'); } else if(skor < 50) { console.log('C'); } else if(skor < 80) { console.log('B'); } else { console.log('A'); } var matematika = 13; var wawancara = 'A'; if(matematika > 60) { var keterangan = 'Lolos tes, dengan predikat '; if(wawancara == 'A') { console.log(keterangan + 'Memuaskan'); } else if(wawancara == 'B') { console.log(keterangan + 'Cukup'); } else { console.log(keterangan + 'Tidak lolos tes'); } } else { console.log('nilai anda kurang mencukupi'); } var binatang = 'ayam'; switch(binatang) { case 'ayam': case 'sapi': case 'kambing': console.log(binatang + ' termasuk hewan herbivora'); break; case 'serigala': case 'harimau': console.log(binatang + ' termasuk hewan karnivora'); break; case 'tikus': console.log(binatang + ' termasuk hewan omnivora'); break; default: console.log(binatang + ' tidak terdaftar di program'); break; } var hero = ['bristleback', 'chaos knight', 'venomancer']; for (hr = 0; hr < hero.length; hr++) console.log((hr + 1) + " " + " " + hero[hr]); //array paprika tidak di print karena tertimpa array index 4 'sawi' var sayuran = ['kangkung', 'bayam', 'kol', 'paprika']; sayuran[0] = 'selada'; sayuran[3] = 'brokoli'; console.log('Output: '); sayuran[4] = 'sawi'; console.log(sayuran) var kuliner = { makanan: 'sate', negara: 'indonesia', } console.log(kuliner) var herbivora = new Array('kerbau', 'sapi'); var karnivora = new Array('harimau', 'serigala'); var omnivora = new Array('ayam', 'monyet'); var binatang = new Array(herbivora, karnivora, omnivora); // Isi Array `binatang` console.log('Binatang: '); console.log(binatang); console.log('array :') console.log(binatang[0]) console.log('jumlah array binatang') console.log(binatang.length) console.log('jumlah array binatang[0] : ' + binatang[0].length + " => " + binatang[0]); console.log('jumlah array binatang[1] : ' + binatang[1].length + " => " + binatang[1]); console.log('jumlah array binatang[2] : ' + binatang[2].length + " => " + binatang[2]); console.log('perulangan while') var whi = 1; while(whi <= 10) { console.log( whi); whi++; } console.log('perulangan do while '); var dowhi = 0; do { console.log( dowhi ); dowhi++; } while(dowhi < 10); console.log('perulangan for ++ 2'); var forpl; for (forpl = 0; forpl <= 10; forpl++) { console.log('nomor : ' + forpl++); } console.log('perulangan for -- 2'); var forpl; for (forpl = 10; forpl >= 0; forpl--) { console.log('nomor : ' + forpl--); } console.log('foreach') var pulau = new Array('papua','nusa tenggara','maluku','sulawesi','kalimantan'); pulau.forEach(function(value, index) { console.log('Indeks ke-' + index + ' adalah pulau ' + value); });
Editor Settings
Theme
Key bindings
Full width
Lines