-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeedGen.js
37 lines (32 loc) · 964 Bytes
/
speedGen.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
30
31
32
33
34
35
36
37
//I have the defined the variables which remain fixed
const speedLim=70;
const kmPerDemirit=5;
function speedChecker(){
let speed =prompt('ENTER YOUR CURRENT SPEED');
speed=Number(speed);
if(isNaN(speed) || speed<0){
console.log('WARNING !!!! BE SERIOUS AND INPUT THE CORRECT SPEED');
alert('WARNING !!!! BE SERIOUS AND INPUT THE CORRECT SPEED')
return;
}
if (speed<=speedLim){
console.log('OK');
alert('OK')
}
else{
calcDemerits(speed);
}
}
function calcDemerits(speed){
let speedExceed=speed-speedLim;
let demeritPoints=Math.ceil(speedExceed/kmPerDemirit);
if(demeritPoints<12){
console.log(`You have : ${demeritPoints} POINTS`);
alert(` You have the : ${demeritPoints} POINTS`);
}
else{
console.log(`LICENCE SUSPENDED ,POINTS: ${demeritPoints}`);
alert(`LICENCE SUSPENDED ,POINTS: ${demeritPoints}`);
}
}
speedChecker();