Skip to content
Advertisement

How can I print an error message if the value is < 250

I have this code where somebody can choose a ppm value and it calculates the fanControl value.

JavaScript

What do I have to do that the program prints an error message and stops calculating if the person who chooses the ppm value, chooses something less than 250.

Advertisement

Answer

I agree with @Federico

Your solution will depend on how you want to handle invalid input

Just change return; to return -1;

Then, whenever/wherever you call fanControl(X), just surround it with a conditional:

JavaScript

Also, make sure your ppm > 250 is changed to ppm >= 250 if you want to include 250 as valid input

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement