Comparison: Number


Requirements

Compare some numbers then determine which one is bigger or smaller.

Input

  • Two or more different numbers

Process

  • Compare number and number

Output

  • Telling which one is bigger or smaller

Level 0

  • Store different numbers into some variables
  • Create some if else statement blocks that tell if each number is bigger or smaller than our determined value
  • Log that results to the console

Level 1

  • Try to compare those numbers with each other
  • Expand the if else statements into multiple chains
if (condition) {
  // code
} else if (condition) {
  // code
} else {
  // code
}

Level 2

  • Use ternary operator ? : rather than if else statement
condition ? resultA : resultB

Level 3

  • Try to compare a variable with value range, with more than 2 conditions, bigger and smaller than some different value at the same time
  • Experiment with various kind of operations
min >= condition >= max
conditionA && conditionB

Level 4

  • Wrap those logics into some functions that can be called later
  • Use parameters to enable us assign different kind of inputs to compare
  • You need at least two parameters for these functions
function process(parameterA, parameterB) {
  // code
}

process()

Level 5

  • Create a random number generator