Skip to content

Commit ac76424

Browse files
added new solved here calculation watchtime, cashout charage, election result, mail validation check, and real friendship check
1 parent ffe92fb commit ac76424

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Problem-10
2+
3+
Subah wastes time watching Tiktok all day. He doesn't study. Subah's father is very worried about Subah wasting this time. Subah's father wants to create a function so that he can see how much time Subah wastes watching videos every day. Your task is to make Subah's father create a function called calculateWatchTime() that will take an Array as input. The Array will store the time (seconds) spent watching Subah's videos as a Number. The function will extract the total time from the Array, convert it to hours, minutes and seconds and return it as an object.*/
4+
5+
function calculateWatchTime(times) {
6+
let watchTime = 0;
7+
for (let time of times) {
8+
if (typeof time !== 'number') {
9+
return "Invalid";
10+
}
11+
watchTime = watchTime + time;
12+
}
13+
let hours = Math.floor(watchTime / 3600);
14+
let minutes = Math.floor((watchTime % 3600) / 60);
15+
let seconds = watchTime % 60;
16+
return { hour: hours, minute: minutes, second: seconds }
17+
18+
19+
}
20+
const times = [1000, 2000, 725];
21+
const result = calculateWatchTime(times);
22+
console.log(result);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Problem-6
2+
3+
Rahim is a small businessman. He has to make various transactions through bKash every day. One day a customer comes to his shop and says, 👉 "Brother, I want to cash out 2000 taka. How much charge will be deducted?"
4+
Rahim started calculating in his mind, but suddenly he thought - it is a hassle to calculate like this repeatedly! What if there was a function, which would take out the charge for any amount given! And since Rahim knows that you are a brilliant student of Programming Hero, your job is -
5+
Rahim to create a function called cashOut() which will take out the cash out charge when money is input.
6+
Cashout Charge is - 1.75% */
7+
8+
function cashOut(money) {
9+
if (typeof money !== 'number' || money < 0) {
10+
return "Invalid";
11+
}
12+
else if (0 < money) {
13+
const charge = money * 1.75 / 100;
14+
return charge;
15+
}
16+
else if (money === 0) {
17+
return 0;
18+
}
19+
}
20+
const result = cashOut(2000);
21+
console.log(result);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Problem-8
2+
3+
The political scene in Bangladesh is in a tense state! Mango-party and Banana-party face off in a great election! Voting is underway, but everyone is confused when it comes to counting! 😵 So, you need to write a function called electionResult(), which will take an Array Input and count the votes and tell you—"Who is the winner?"
4+
5+
If "mango" is more than one in the Array then the function will return "Mango"
6+
If "banana" is more than one in the Array then the function will return "Banana"
7+
If "mango" and "banana" are equal then it will return "Draw"
8+
9+
*/
10+
11+
function electionResult(votes) {
12+
if (!Array.isArray(votes)) {
13+
return "Invalid";
14+
}
15+
let mangoVotes = 0;
16+
let bananaVotes = 0;
17+
for (let vote of votes) {
18+
if (vote === "mango") {
19+
mangoVotes++;
20+
}
21+
else if (vote === "banana") {
22+
bananaVotes++;
23+
}
24+
}
25+
if (mangoVotes > bananaVotes) {
26+
return "Mango";
27+
28+
}
29+
else if (bananaVotes > mangoVotes) {
30+
return "Banana";
31+
}
32+
else if (mangoVotes === bananaVotes) {
33+
return "Draw";
34+
}
35+
36+
}
37+
const array = ["mango", "BananA", "na vote", "na vote"];
38+
const result = electionResult(array);
39+
console.log(result);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Problem-7
2+
3+
Your task is to create a function called validEmail(), which will take an email input and return a boolean value (true/false) to check whether it is correct or not.
4+
The conditions for an email to be valid are
5+
The email must not have special characters like ".-_+@" at the beginning.
6+
The email must have @ in the middle.
7+
The email must not have any spaces.
8+
The email must have .com at the end.
9+
If the above conditions are met, it will return true as the output. Otherwise, it will return false as the output. */
10+
11+
function validEmail(email) {
12+
if (typeof email !== 'string') {
13+
return "Invalid";
14+
}
15+
let firstChar = email.charAt(0);
16+
if (email.includes(" ") || !email.endsWith(".com") || !email.includes("@") || ".-_+@".includes(firstChar)) {
17+
return false;
18+
}
19+
return true;
20+
21+
}
22+
const result = validEmail("[email protected]");
23+
console.log(result);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Problem-9
2+
3+
📢 Is friendship just a word? Or is it real? 🧐 You need to write an isBestFriend() function that will check if the friendship between two friends is real! 🔍
4+
Your function will be given data of 2 friends. If the value of the first person's bestFriend matches the roll of the second person and the value of the second person's bestFriend matches the roll of the first person, then we will understand that they are two true best friends. */
5+
6+
function isBestFriend(f1, f2) {
7+
if (typeof f1 !== 'object' || typeof f2 !== 'object') {
8+
return "Invalid";
9+
}
10+
else if (f1.bestFriend === f2.roll && f2.bestFriend === f1.roll) {
11+
return true;
12+
}
13+
else {
14+
return false;
15+
}
16+
}
17+
const f1 = { name: "hashem", roll: 1, bestFriend: 1 };
18+
const f2 = { name: "kashem", roll: 1, bestFriend: 1 };
19+
const result = isBestFriend(f1, f2);
20+
console.log(result);

0 commit comments

Comments
 (0)