আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা দুটি সংখ্যা নেয়, মনে করুন num1 এবং num2।
num1, num2-র চেয়ে বড় হলে, ফাংশনটি 'greater' ফেরত দেবে।
num2, num1-র চেয়ে বড় হলে, ফাংশনটি 'smaller' ফেরত দেবে।
অন্যথায়, ফাংশনটি 'equal' ফেরত দেবে।
উদাহরণ
নিচে কোড দেওয়া হল −
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