forked from JoinCODED/TASK-JS-Functions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge1.js
More file actions
59 lines (56 loc) · 1.35 KB
/
challenge1.js
File metadata and controls
59 lines (56 loc) · 1.35 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
/**
* Task 1:
* Create a function named `printName`
* - that just prints your name on the screen
*/
function printName() {
console.log("turki almutairi");
}
printName();
/**
* Task 2:
* Create a function named `printAge`
* - that takes a birth year as a parameter,
* - and prints the age on the screen.
* - Age = current year - birth
*/
function printAge(dob) {
return 2023 - dob;
}
console.log(printAge(1995));
/**
* Task 3:
* Create a function named `printHello`
* - that takes 2 parameters, name, and language
* - language can be passed in different values, here are the accepted values:-
* -- en: it should print `Hello NAME`
* -- es: it should print `Hola NAME`
* -- fr: it should print `Bonjour NAME`
* -- tr: it should print `Merhaba NAME`
*/
function printHello(name, language) {
if (language == `en`) {
console.log(`hello ${name}`);
} else if (language == `es`) {
console.log(`Hola ${name}`);
} else if (language == `fr`) {
console.log(`Bonjour ${name}`);
} else if (language == `tr`) {
console.log(`merhaba ${name}`);
}
}
printHello(`turki`, `tr`);
/**
* Task 4:
* Create a function named `printMax`
* - that takes 2 parameters as numbers
* - should print out the bigger number
*/
function printMax(num1, num2) {
if (num1 > num2) {
return num1;
} else {
return num2;
}
}
console.log(printMax(100, 20));