desito07

Road Radar

May 23rd, 2021
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(speed, area) {
  2.   let diff = 0;
  3.   switch (area) {
  4.     case "motorway":
  5.       diff = speed - 130;
  6.       break;
  7.     case "interstate":
  8.       diff = speed - 90;
  9.       break;
  10.     case "city":
  11.       diff = speed - 50;
  12.       break;
  13.     case "residential":
  14.       diff = speed - 20;
  15.       break;
  16.   }
  17.  
  18.   if (diff <= 20 && diff > 0) {
  19.     console.log(
  20.       `The speed is ${diff} km/h faster than the allowed speed of 20 - speeding`
  21.     );
  22.   } else if (diff < 40 && diff > 0) {
  23.     console.log(
  24.       `The speed is ${diff} km/h faster than the allowed speed of 90 - excessive speeding`
  25.     );
  26.   } else if (diff > 40 && diff > 0) {
  27.     console.log(
  28.       `The speed is ${diff} km/h faster than the allowed speed of 130 - reckless driving`
  29.     );
  30.   }
  31.   if (diff < 0) {
  32.     console.log(`Driving ${speed} km/h in a 50 zone`);
  33.   }
  34. }
  35. solve(40, "city");
  36. solve(21, "residential");
  37. solve(120, "interstate");
  38. solve(200, "motorway");
  39.  
Advertisement
Add Comment
Please, Sign In to add comment