Home > Software engineering >  Given 3 numbers N , L and R. Print 'yes' if N is between L and R else print 'no'
Given 3 numbers N , L and R. Print 'yes' if N is between L and R else print 'no'

Time:11-07

Given 3 numbers N , L and R. Print 'yes' if N is between L and R else print 'no'. Sample Testcase : INPUT 3 2 6 OUTPUT yes

How to solve this problem using javascript, I can't even understand the question,So please help me to solve this....

CodePudding user response:

N is between L and R meaning if (N > L && N < R){} so in your example (3, 2, 6) => N = 3, L = 2 and R = 6 so 3 in between 2 and 6.

const check = (N, L, R) => {
  if (N > L && N < R) return "yes";
  return "no";
}

console.log(check(3,2,6));

CodePudding user response:

Those letters are supposed to be variables which contain a given number value. You want to check and see if the value in N is greater than the value in L but less than the value in R. For instance,

let L = 2
let N = 3
let R = 6

if (N > L && N < R) {
    console.log("Yes")}
else {
    console.log("No")}

So you're printing "yes" if 3 is greater than 2 AND less than 6, and you're printing "no" if it's not. And, of course, the only reason it would ever print "No" instead of "Yes" would be if your N variable contained a different number outside the range of the values in your other variables. For instance, if you changed the value in your N variable to contain the number 7 it would print "No."

  • Related