Task: if a more than b more than 10 , output a + 10 ; otherwise, if a less than b , print 9 ; otherwise b )

 if (a > b && a > 10) { console.log(a + 10); } else { console.log(a + 9); } 
  • const f = (a, b) => a - 10 > b ? a + 10 : a < b ? 9 : b; - Yaant September

2 answers 2

 function getNumber(a, b) { if (a - 10 > b) return a + 10; if (a < b) return 9; return b; } console.log(getNumber(12, 1)); // 22 console.log(getNumber(1, 11)); // 9 console.log(getNumber(12, 5)); // 5 

  • Please explain why a - 10? - Dmitry Walker
  • @DmitryWalker "a is more than b by more than 10" means that if you subtract 10 from a , then the resulting value must be greater than b . You can write in a different way. a > b + 10 . - Suvitruf
  • Thank! now understood - Dmitry Walker
  • @DmitryWalker is great. So I knowingly wrote the answer) - Suvitruf

If a is more than b by more than 10 (pseudocode)

 (a - b > 10) -> a + 10 

If a is less than b

 (a < b) -> 9