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 :

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);

Leave a Reply