-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
67 lines (54 loc) · 1.91 KB
/
script2.js
File metadata and controls
67 lines (54 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// TUGAS 1
function kirim(){
let username = document.getElementById("inputUsername").value;
let password = document.getElementById("inputPassword").value;
if (username == "" || password == ""){
alert("Mohon lengkapi data diatas")
} else {
cek = confirm("Apakah data diatas sudah benar?")
if (cek == true ){
alert("Login berhasil")
} else {
alert("Silahkan isi data kembali")
}
}
}
const tombol = document.getElementById("btn");
tombol.addEventListener("click", kirim)
// TUGAS 2
function submitted(){
var nama = document.getElementById("inputName").value;
var email = document.getElementById("inputEmail").value;
var pesan = document.getElementById("pesan").value;
if (nama == "" || email == "" || pesan == ""){
swal({
title: "Pesan Gagal Terkirim!",
text: "Tidak boleh ada form yang kosong",
icon: "error",
});
} else {
swal({
title: "Pesan Berhasil Terkirim!",
text: "Nama :" + nama + "\nEmail :" + email + "\nPesan :\n" + pesan,
icon: "success",
});
}
}
let buttonSubmit = document.getElementById("contactUs");
buttonSubmit.addEventListener("click", submitted);
// TUGAS 3
let apel = document.getElementById("apel")
let anggur = document.getElementById("anggur")
let jeruk = document.getElementById("jeruk")
apel.addEventListener("click", pilih.bind(this,"apel"))
anggur.addEventListener("click", pilih.bind(this,"anggur"))
jeruk.addEventListener("click", pilih.bind(this,"jeruk"))
function pilih(buah){
if(buah == "apel"){
alert("Kamu memilih apel")
} else if (buah == "anggur"){
alert("Kamu memilih anggur")
} else if (buah == "jeruk"){
alert("kamu memilih jeruk")
}
}