JSFAR

 avatar
user_5249784
javascript
9 days ago
3.0 kB
2
Indexable
Never
\\JS1
var n = prompt("Masukkan Nama Anda : ");
var c = confirm("Hai " + n + " ! Apakah saya tampan ? ");
if (c == true) {
    alert("Oh Thanks!!");
} else
    alert("Why ?!!");
}

\\JS6
var txt = "";
var numbers = [45, 4, 9, 16, 25];
numbers.forEach(myfunction);

function myfunction(value, index, array){
    document.write(txt+ value + "<br>");
}

\\JS7
switch (new Date().getDay()) {
    case 0:
        console.log("Sunday");
        break;
    case 1:
        console.log("Monday");
        break;
    case 2:
        console.log("Tuesday");
        break;
    case 3:
        console.log("Wednesday");
        break;
    case 4:
        console.log("Thursday");
        break;
    case 5:
        console.log("Friday");
        break;
    case 6:
        console.log("Saturday");
        break;

    default:
        console.log("Where Are You Living!?");
}

\\JS8
alert("Selamat Datang di Javascript ");

\\JS9
var confirmation = confirm("Do you want to go to another world?")
if (confirmation) {
    alert("You pick to go to another world received blessings from that world");
    { else }
    alert("You pick to stay on earth and survive to archive your life goal");
}

\\JS10
var age = prompt("How old are you");
alert("Your are " + age + " years old");

\\JS11
var mahasiswa = {
    nama: 'Ajay Alfredo Almani',
    npm: 50420093,
    kelas: '2IA16',
    jurusan: 'Teknik Informatika',
    IPSemester: [3.14, 3.20, 3.67, 3.73, 3.74],
    IPKumulatif: function () {
        var total = 0;
        var ip = this.IPSemester;
        for (var i = 0; i < ip.length; i++) {
            total += ip[i];
        }
        return total / ip.length;
    }
}
mahasiswa.IPKumulatif();

\\JS12
var mobil = {
    nama: "Xpander",
    merek: "Mitsubishi",
    tipemobil: "Mini Jeep",
    tahundibuat: 2007,
    warna: "putih",
    majukencang: function () {
        console.log("Mobil ini melaju dengan kecepatan 300Km/h");
    },
    majupelan: function () {
        console.log("Mobil ini melaju dengan kecepatan 10Km/h");
    },
    mundur: function () {
        console.log("Mobil ini melaju kebelakang");
    },
    stop: function () {
        console.log("Mobil ini berhenti");
    }
};

\\JS13
var mhs = {
    nama: "Ajay Alfredo Almani ",
    npm: "50420093",
    email: "ajaycibuntu@gmail.com",
    jurusan: "Teknik Informatika"
}

var mhs2 = {
    nama: "Elia Dania S",
    npm: "50420416",
    email: "eliadania86@gmail.com",
    jurusan: "Teknik Informatika"
}

\\JS14
function buatobject(nama, npm, email, jurusan) {
    var mhs = {},
        mhs.nama = nama;
    mhs.npm = npm;
    mhs.email = email;
    mhs.jurusan = jurusan;
    return mhs;
}

\\JS15
function mahasiswa(nama, npm, email, jurusn) {
    this.nama = nama;
    this.npm = npm;
    this.email = email;
    this.jurusan = jurusan;
}
var mhs4 = new mahasiswa("Ajay Alfredo Almani", 50420093, "ajaycibuntu@gmail.com", "Teknik Informatika")