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
64 lines (57 loc) · 1.37 KB
/
challenge1.js
File metadata and controls
64 lines (57 loc) · 1.37 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
/**
* Task 1:
* Create a function named `printName`
* - that just prints your name on the screen
*/
function printName(name) {
console.log(`My name is ${name}`);
}
printName("wahab");
/**
* 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(birthYear) {
let age = 2023 - birthYear;
console.log(age);
}
printAge(1999);
/**
* 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, lang) {
if (lang == "en") {
console.log(`Hello ${name}`);
} else if (lang == "es") {
console.log(`Hola ${name}`);
} else if (lang == "fr") {
console.log(`Bonjour ${name}`);
} else if (lang == "tr") {
console.log(`Merhaba ${name}`);
}
}
printHello("wahab", "es");
/**
* 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) {
console.log(num1);
} else {
console.log(num2);
}
}
printMax(10, 5);