আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা দুটি সংখ্যায় লাগে, আসুন num1 এবং num2 বলি৷
-
যদি num1 num2 এর থেকে বড় হয়, তাহলে আমাদের ফাংশনটি আরও বড় হওয়া উচিত।
-
যদি num2 num1 এর থেকে বড় হয়, তাহলে আমাদের ফাংশন ছোট হতে হবে।
-
অন্যথায়, ফাংশনটি সমান হওয়া উচিত।
উদাহরণ
নিম্নলিখিত কোড -
const compareIntegers = (num1, num2) => {
if(typeof num1 !== 'number' || typeof num2 !== 'number'){
return false;
};
if(num1 > num2){
return 'greater';
}else if(num2 > num1){
return 'smaller';
}else{
return 'equal';
};
};
console.log(compareIntegers(12, 56));
console.log(compareIntegers(72, 56));
console.log(compareIntegers(12, 12));
console.log(compareIntegers(12, 33)); আউটপুট
নিম্নোক্ত কনসোলে আউটপুট -
smaller greater equal smaller