Mahdicoding1987 / js-functions-lab

0 stars 0 forks source link

Consider accounting for unintended arguments #2

Open KhalilKhunji opened 1 month ago

KhalilKhunji commented 1 month ago

https://github.com/Mahdicoding1987/js-functions-lab/blob/ff8d43616d84ba6e519ce41dba02530b47ce339a/exercise-8.js#L1-L4 https://github.com/Mahdicoding1987/js-functions-lab/blob/ff8d43616d84ba6e519ce41dba02530b47ce339a/exercise-9.js#L1-L6

I'd like you to consider a scenario when the functions here take arguments they aren't intended to. Such as the scale receiving 'K' for Kelvin, or the operation receiving a non-string datatype, or something other than the specified options.

As it is right now, if those functions receive unintended arguments, they'll simply return undefined.

It's good practice to use the final else statement in an if statement chain to account for that scenario. E.g. you could have the Ex 8 function return 'Invalid scale' when receiving anything other than 'F' or 'C'. Depending on your needs, you might even prefer to have it return something indicative of why it's invalid (e.g. returning the erroneous datatype received into operation, such as a number, or even an object!).

Just food for thought; no real problems with the way you solved them!

Mahdicoding1987 commented 1 month ago

Thanks for your feedback.