Skip to content

Commit 83a4a5b

Browse files
adde new function and learnt new elements
1 parent fbebfec commit 83a4a5b

File tree

6 files changed

+133
-0
lines changed

6 files changed

+133
-0
lines changed

F. Function/average.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Problem-3
2+
3+
Write a function called make_avg() which will take an array of integers and the size of that array and return the average of those values.
4+
5+
*/
6+
function make_avg(numbers) {
7+
const inputSize = numbers.length;
8+
console.log("Size of the array", inputSize);
9+
let sum = 0;
10+
for (let i = 0; i < inputSize; i++) {
11+
sum = sum + numbers[i];
12+
}
13+
const average = sum / inputSize;
14+
return average;
15+
}
16+
const input = [2, 4, 6, 8, 10];
17+
const result = make_avg(input);
18+
console.log("Average Number = ", result);

F. Function/conditional-multiply.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Problem-2
2+
3+
Take a number if the number is odd multiply it by 2 and return the result. If the number is even divide it by two and return the result.
4+
5+
*/
6+
function numbers(number) {
7+
if (number % 2 === 1) {
8+
const odd = number * 2;
9+
return odd;
10+
}
11+
12+
else {
13+
const even = number / 2;
14+
return even;
15+
}
16+
}
17+
const oddResult = numbers(15); //odd number just for check
18+
const evenResult = numbers(10); //even number just for check
19+
console.log(oddResult);
20+
console.log(evenResult);

F. Function/count-number.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Problem-4
2+
3+
Write a function called count_zero() which will take a binary string (Binary string is a string which is consist of only 0 and 1) as parameter and count how many 0’s are there in that string.
4+
*/
5+
6+
function count_zero(numbers) {
7+
let numberZero = 0;
8+
for (let i = 0; i < numbers.length; i++) {
9+
if (numbers[i] === '0') {
10+
numberZero++;
11+
}
12+
}
13+
return numberZero;
14+
}
15+
const input = "10100101001000011000";
16+
const result = count_zero(input);
17+
console.log(result);

F. Function/even-odd.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Problem-5
2+
3+
Write a function called odd_even() which takes an integer value and tells whether this value is even or odd. If even return Even. If odd return Odd
4+
*/
5+
6+
function odd_even(numbers) {
7+
if (numbers % 2 === 0) {
8+
return "Even";
9+
}
10+
else {
11+
return "Odd"
12+
}
13+
}
14+
15+
const oddEven = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
16+
const result = odd_even(oddEven);
17+
console.log(result);

F. Function/func.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Your task is to calculate the total budget required to buy electronics:
2+
3+
laptop = 35000 tk
4+
tablet = 15000 tk
5+
mobile = 20000 tk
6+
Write a JavaScript function named calculateElectronicsBudget that takes in the number of laptop, tablets, and mobile and returns the total money required.
7+
8+
9+
task 4
10+
11+
You are given an array of phone objects, each containing information about the model, brand, and price. Your task is to write a JavaScript function named findAveragePhonePrice that takes this array as input and returns the average price of phone.
12+
13+
Input
14+
15+
16+
const phones = [
17+
{ model: "PhoneA", brand: "Iphone", price: 95000 },
18+
{ model: "PhoneB", brand: "Samsung", price: 40000 },
19+
{ model: "PhoneC", brand: "Oppo", price: 26000 },
20+
{ model: "PhoneD", brand: "Nokia", price: 35000 },
21+
{ model: "PhoneE", brand: "Iphone", price: 105000 },
22+
{ model: "PhoneF", brand: "HTC", price: 48000 },
23+
];
24+
25+
task 5
26+
27+
For each employee their current salary is calculated by multiplying yearly increment with experience then adding the result to the starting salary. Now calculate is the total salary has to be provided by the company in a month.
28+
29+
const employees = [
30+
{ name: "shahin", experience: 5, starting: 20000, increment: 5000 },
31+
{ name: "shihab", experience: 3, starting: 15000, increment: 7000 },
32+
{ name: "shikot", experience: 9, starting: 30000, increment: 1000 },
33+
{ name: "shohel", experience: 0, starting: 29000, increment: 4000 },
34+
];
35+

F. Function/multiply.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Problem-1
2+
3+
Take four parameters. Multiply the four numbers and then return the result
4+
5+
*/
6+
7+
8+
// solution-1 by simple call back function
9+
10+
function multiply(a, b, c, d) {
11+
const multiplyResult = a * b * c * d;
12+
console.log(multiplyResult);
13+
}
14+
multiply(2, 5, 6, 10);
15+
16+
17+
18+
19+
// Solution-2 by return
20+
21+
function multi(a, b, c, d) {
22+
const result = a * b * c * d;
23+
return result;
24+
}
25+
const output = multi(2, 5, 6, 10);
26+
console.log(output);

0 commit comments

Comments
 (0)