Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(speed, area) {
- let diff = 0;
- switch (area) {
- case "motorway":
- diff = speed - 130;
- break;
- case "interstate":
- diff = speed - 90;
- break;
- case "city":
- diff = speed - 50;
- break;
- case "residential":
- diff = speed - 20;
- break;
- }
- if (diff <= 20 && diff > 0) {
- console.log(
- `The speed is ${diff} km/h faster than the allowed speed of 20 - speeding`
- );
- } else if (diff < 40 && diff > 0) {
- console.log(
- `The speed is ${diff} km/h faster than the allowed speed of 90 - excessive speeding`
- );
- } else if (diff > 40 && diff > 0) {
- console.log(
- `The speed is ${diff} km/h faster than the allowed speed of 130 - reckless driving`
- );
- }
- if (diff < 0) {
- console.log(`Driving ${speed} km/h in a 50 zone`);
- }
- }
- solve(40, "city");
- solve(21, "residential");
- solve(120, "interstate");
- solve(200, "motorway");
Advertisement
Add Comment
Please, Sign In to add comment