Advertisement
pacho_the_python

road_radar

Feb 22nd, 2023
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function roadRadar(speed, area) {
  2.     let speed_limits = {
  3.         'motorway': 130,
  4.         'interstate': 90,
  5.         'city': 50,
  6.         'residential': 20,
  7.     };
  8.  
  9.     function get_status(number) {
  10.         let status = '';
  11.         if (number <= 20) {
  12.             status = 'speeding';
  13.         }
  14.         else if (20 < number && number <= 40 ) {
  15.             status = 'excessive speeding';
  16.         }
  17.         else if (number > 40) {
  18.             status = 'reckless driving';
  19.         }
  20.         return status
  21.     }
  22.     if (speed <= speed_limits[area]) {
  23.         return console.log(`Driving ${speed} km/h in a ${speed_limits[area]} zone`);
  24.     }
  25.     let diff = speed - speed_limits[area];
  26.     let current_status = get_status(diff);
  27.     let current_speed_limit = speed_limits[area];
  28.     console.log(`The speed is ${diff} km/h faster than the allowed speed of ${current_speed_limit} - ${current_status}`);
  29. }
  30.  
  31. roadRadar(200, 'motorway')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement