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

how to Write for every 5 units in JavaScript?

I want to write a function that receives the speed of a machine. Give a negative score for every 5 km / h increase of more than 74 km / h, and if, for example, the speed becomes 80
Give a negative score of 2 if 85
3 negative scores

>Solution :

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

you are describing a mathematical formula that If I got right is:
give negative point for every X (5 in our case) Km/h above threshold T
you can just write:

function(speed) {
  const T = 74;
  const X = 5;
  return Math.floor((speed-T)/X);
}
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