Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function roadRadar(array) {
- const zones = {
- 'city': 50,
- 'motorway': 130,
- 'interstate': 90,
- 'residential': 20,
- checker: function checker(speed, limit) {
- if (speed > limit && speed <= limit + 20) {
- console.log('speeding');
- } else if (speed > limit + 20 && speed <= limit + 40) {
- console.log('excessive speeding');
- } else if (speed > limit + 40) {
- console.log('reckless driving');
- }
- }
- };
- for (let i = 0; i < array.length; i++) {
- let speed = Number(array[i]);
- let zone = array[i + 1];
- zones.checker(speed, zones[zone]);
- }
- }
- roadRadar([200, 'motorway']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement