-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
43 lines (29 loc) · 978 Bytes
/
functions.js
File metadata and controls
43 lines (29 loc) · 978 Bytes
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
// Write a function helloWorld that simply returns the string "Hello, World!".
function helloWorld() {
return "Hello, World!";
}
console.log(helloWorld());
// Write a function addNumbers that takes two parameters (numbers) and returns their sum.
function sum(num1, num2) {
return num1 + num2;
}
console.log(sum(12, 12));
// Write a function multiplyNumbers that takes two parameters (numbers) and returns their product.
function product(num1, num2) {
return num1 * num2
}
console.log(product(12,12));
// Write a function stringLength that takes a string as a parameter and returns its length.
function strlength(str) {
return str.length
}
console.log(strlength("Muhammad Shakir"));
// Write a function isEven that takes an integer as a parameter and returns true if it's even and false if it's odd.
function isEvenOdd(num) {
if (num % 2 === 0) {
return "Even";
} else {
return "Odd";
}
}
console.log(isEvenOdd(12));