In the “Build a Library” project we create a parent class, named Media, that has a method for adding ratings, the “.addRating()” method. If we want to make sure input is between 1
and 5
, we can use “Math.min(Math.max(number, 1), 5)” or we also can use an “if” statement. So, why use the Math.min and Math.max instead of the if statemet? Is there any advantage?
https://www.codecademy.com/courses/learn-intermediate-javascript/projects/build-a-library
Thank you!