Hey guys, i could really use some help here. I’ve tried countless times to understand what Mosh did here, but i haven’t been able to. I’d really appreciate any help.
Hi,
I don’t take his JS course so I don’t know the full code but it seems it is computing a number of points you remove from a driving license.
So if your speed is under the speed limit you just display OK.
Else you may have several scenarios.
The first step is common to each and it computes the number of points to remove.
I believe the kmPerpoint
(kpp) identifier is a constant for which you remove 1 pt on the license.
So say the speed limit is 50 Km/h and the kpp
is 2.
You drive at 52 Km/h you are removed 1 point. 60Km/h you are removed 5 points.
The formula is flooring the delta between speed and the limit divided by kpp
.
Should you need to understand Math.floor
see the doc @MDN. For short it rounds to the closest integer bellow the value.
Here are samples.
S | S_{L} | Δ_{SSL} | R1 | R_{Total} | Effect |
---|---|---|---|---|---|
0 | 50 | -50 | -25 | -25 | OK |
50 | 50 | 0 | 0 | 0 | OK |
100 | 50 | 50 | 25 | 25 | L.S. |
60 | 50 | 10 | 5 | 5 | -5 Pts |
35 | 50 | -15 | -7.5 | -8 | OK |
65 | 50 | 15 | 7.5 | 7 | -7 Pts |
73 | 50 | 23 | 11.5 | 11 | -11 Pts |
Columns:
- S: Current Speed
- S_{L}: Speed Limit
- Δ_{SSL}: Difference between current speed and limit
- R1: Result of Δ_{SSL} divided by
kpp
- R_{Total}: Final result
kpp
has the value of 2.
Effects:
- OK: You can go ahead without any consequence
- L.S. : License Suspended
- -X Pts: Number of points removed where X is that number of points.
So:
- Over 12 points included your license is removed.
- Under 12 points you remove the computed amount of points.
I hope this helped you understand.
Good luck with your course.
Please elaborate
I took a better screenshot, so you’ll be able to see the code fully
Well thanks for the updated screenshot. It confirms my thoughts.
Better than screenshot copy paste your code should you ask new questions in the future. This would make anyone’s life trying to help easier.
You can use markdown to surround your code. This is simple to learn and useful when you write documentations.
Now I don’t see how I could elaborate anymore. Please read my answer carefully.