-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed.js
30 lines (24 loc) · 966 Bytes
/
speed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function speedDetector(speed) {
const speedLimit = 70;
//setting the speed limit to be 70
//set number of km per demerit point to 5
//use if else statement to check the driving speed against the speed limit.
// if the first condition is met, output "Ok"
//if the car speed exceeds the limit, calculate the number of points based on the km.
//if the points calculated exceeds 12, console.log "license suspended"
// Check if you are below the speed limit
if (speed < speedLimit) {
console.log("Ok");
} else {
// Calculating demerit points
let demeritPoints = Math.floor((speed - speedLimit) / 5);
console.log("Points: " + demeritPoints);
// Check if your license is suspended
if (demeritPoints > 12) {
console.log("License suspended");
}
}
}
//test the function with any speed
let carSpeed = 120;
speedDetector(carSpeed);