-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path34-Function_Return_Value.html
59 lines (50 loc) · 1.41 KB
/
34-Function_Return_Value.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Function Return Value</title>
</head>
<body>
<script>
// membuat function
function sayHeloWolrd(myFriend, mySelf) {
const say = `<p>Hello ${myFriend} kenalin nama saya ${mySelf}</p>`;
return say;
}
// masukan value function kedalam variabel
const result = sayHeloWolrd('riki', 'aswad');
// tampilkan isi variabel result ke web
document.writeln(result);
// function yang returnnya lebih dari satu
function getFinalScore(score) {
if (score > 90) {
return 'A';
} else if (score > 80) {
return 'B';
} else if (score > 70) {
return 'C';
} else {
return 'D';
}
}
const finalScore = getFinalScore(76);
document.writeln(`<p>${finalScore}</p>`);
// menghentikan eksekusi dengan return
function isContains(array, searchValue) {
for (const element of array) {
console.log(`Iterasi Element ${element}`);
if (element === searchValue) {
return true;
}
}
return false;
}
const array = [1, 52, 3553, 45, 33, 10, 55, 6];
const search = 10;
const found = isContains(array, search);
document.writeln(`<p>${found}</p>`);
</script>
</body>
</html>