Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get the resulting number with js

So basically my problem is that am trying to figure out how to calculate and return a number with JS according to the following logic.

Ex: i have a number of 120 i want to check well is the number greater than 100 ( yes ) okay is the number less than 200 ( yes ) then return ( 1 * 300 )

Ex : another number as 230 is the number greater than 200 ( yes ) okay is the number less than 300 ( yes ) then return ( 2 * 300 )

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

and sooo on.

i made it through switch case but it think it is too odd to do this and it is possible to deal with large numbers like 10000 , 20000 so i will need endless switch cases or if conditions

i hope you got my point

>Solution :

As per the comment above, not considering edge cases (negative numbers for example), you might go with:

Math.floor(n / 100) * 300
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading