Compare some numbers then determine which one is bigger or smaller.
- Two or more different numbers
- Compare number and number
- Telling which one is bigger or smaller
- 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
- 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
}
- Use ternary operator
? :
rather thanif else
statement
condition ? resultA : resultB
- 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
- 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()
- Create a random number generator