Que.1 Calculator
const Calculator = (A, B, C) =>
{
switch (A) {
case "+":
return B + C;
case "-":
return B - C;
case "*":
return B * C;
case "/":
return B / C;
default:
return "Invalid operator";
}
};
Que.2 Check whether the condition is fulfilled or not?
const Check_divisibility = (N) => {
if (N % 6 === 0 && N % 9 === 0) {
return `Divisible by both`;
} else {
return `Not Divisible by both`;
}
};
Que.3 Eligible Voter
const isEligible = (a) => {
if(a>=18){
return 'Eligible for Voting';
}
else{
return 'Not Eligible for Voting'
}
};
Que.4 Find Relation
const findRelation = (x,y) => {
if (x < y) {
return `${x} is smaller than ${y}`;
} else if (x > y) {
return `${x} is greater than ${y}`;
} else {
return `${x} is equal to ${y}`;
}
};
Que.5 Find Grades
const findGrades = (a) => {
switch (true) {
case a <= 10:
return 'E';
case a <= 20:
return 'D';
case a <= 30:
return 'C';
case a <= 40:
return 'B';
case a <= 50:
return 'A';
default:
return 'Invalid marks';
}
};
Que.6 Get Value
const getValue = (a) => {
if(a==='P' || a==='p'){
return 'PrepBytes';
}
else if(a==='Z' || a==='z'){
return 'Zenith';
}
else if(a==='E' || a==='e'){
return 'Expert Coder';
}
else if(a==='D' || a==='d'){
return 'Data Structure';
}
};
Que.7 Find the maximum out of three numbers.
const Max_out_of_three = (A,B,C) => {
let max = A;
if (B > max) {
max = B;
}
if (C > max) {
max = C;
}
// If all three numbers are the same, return 1
if (A === B && B === C) {
return -1;
} else {
// Otherwise, return the maximum of the three numbers
return max;
}
};
Que.8 Second Smallest
const findSndSmallest = (x,y,z) => {
const sorted = [x, y, z].sort((a, b) => a - b);
// Return the second smallest element (the middle element of the sorted array)
return sorted[1];
};
Que.8 Check whether the triangle is Acute or Obtuse
const Triangle_Check = (A,B,C) => {
if (A + B + C === 180) {
// The triangle is valid, so check if it is acute or obtuse
if (A < 90 && B < 90 && C < 90) {
return 'acute';
} else {
return 'obtuse';
}
} else {
// The triangle is invalid
return 'The triangle is invalid';
}
};