Given 2 user specified values, generate all numbers in a set range. When a number is divisible by the first value, display "Fizz" instead. When a number is divisible by the second value, display "Buzz" instead. When a number is divisible by both values, display "FizzBuzz".
I've explained this challenge more in depth here. But here's a quick breakdown of the steps I'd take.
Make a form to get the user input values.
Validate the inputs and display helpful error messages.
If the input is indeed valid, generate all the numbers from the start value to the end value and store them in an array.
Loop through this array and evaluate each number against some conditions.
Check for the most specific condition first, because of how if/else-if conditions are evaluated. If a condition is found to be true, the executor does not evaluate the following condition anyway. So if a broader condition is checked first, the more specific condition wouldn't be evaluated and that's not what we'd want.
Upon the divisible condition being true, replace the value with the corresponding string.
0 Comments