forked from uciharis/materi_masEko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path35_return-value.js
executable file
·39 lines (37 loc) · 1.11 KB
/
35_return-value.js
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
//secara default, function tdk menghasilkan value apapun
//agar menghasilkan value, kita gunakan return dalam function
//return diikuti dengan value yg ingin kita hasilkan
//function hanya bs mengembalikan 1 data,
//utk mengembalikan beberapa data, gunakan array sbg return value
//contoh:
function sayH(firstN,lastN){
const say=`hello ${firstN} ${lastN}`;
return say;
}
const a=sayH("joko","dok");
console.log(a);
function getScore(value){
if(value>90) {
return `nilai ${value} = A`;
} else if(value>80){
return `nilai ${value} = B`;
}else if(value>70){
return `nilai ${value} = C`;
}else if(value>60){
return `nilai ${value} = D`;
}else {
return `nilai ${value} =goblok parah`
}
}
let cek=getScore(77);
console.log(cek);
//return juga bs digunakan utk menghentikan eksekusi function
function isContain(array, cariValue){
for (const element of array){
if (element===cariValue){
return `ada ${cariValue} di ${array}`;
}
}return `tidak ada ${cariValue} di ${array}`;
}
const b=isContain([2,3,4,3,2,3,4,3,2],3);
console.log(b);