Help me to make a small program

Hello Everyone, I would be very happy if u guys help me to make a small program based on the following details. I just need u to help me only the script part specially how to write the first condition. cheers Smile | :slight_smile:

If a car driver speeds no more than 20 km/h over the speed limit, the driver will avoid the income-based unit fines , and gets just the infraction fine . Make a program that tells how much the infraction fine is. It’s based on the speed limit and the excess speed. The program asks for the driving speed and the speed limit. If there is speeding the ticket will be decided upon based on the following rules:
If the speed limit is 10-60 kilometers an hour, and the excess speed is no more than 15 km/h, the speeding leads into a 85-euro infraction fine . More than 15 but no more than 20 km/h leads into an infraction fine of 115 euros.
If the speed limit is 70-120 kilometers an hour, a max 15 km/h speeding will be penalizes with 70-euro infraction fine. The infraction fine is 100 euros when the excess speed is more than 15 km/h, but no more than 20 km/h.
(If the driver drives more than 20 km/h over the limit => he will get unit fines,.

What happens when the speed is between 60 and 70?

What should the your program do when 10-60 drives faster than 80, or when 70-120 gets unit fines?

Hi @draganlimon. Is this a school assignment? Have you made a attempt at it? If so, maybe you could show us what you have so far so we can give you some guidance.

var a=document.getElementById("drivingSpeed").value;
      var b=document.getElementById("speedLimit").value;
      var c=a-b;
      
      if(a>=10 && a<=60 && c <=15) {
        
        document.getElementById("answer").innerHTML="speeding leads into a 85-euro infraction ";

yes…this is a school assignment. I have been trying to do so but can not put the condition correctly. thats why i posted if anybody just help me to write the first condition.

I can not convert the following line into condition

(If the speed limit is 10-60 kilometers an hour, and the excess speed is no more than 15 km/h, the speeding leads into a 85-euro infraction fine . More than 15 but no more than 20 km/h leads into an infraction fine of 115 euros.)

It can help to get the excess in to a variable. For example:

var excess = driverSpeed - speedLimit;
if (excess > 1 && excess < 15) {
    ...
}

First of all, you really should use meaningful variable names. Otherwise, when your criot gets longer and more involved it will be hard to follow.

var drivingSpeed = document.getElementById("drivingSpeed");

Did you test that first conditional? It looks like it should work. What problem are you having with it?

1 Like

This seems to be a more difficult programming task than I initially gave it credit for.

Here’s some working code, complete with a slider to select the driving speed.
Although, it seems that the slider doesn’t show in the preview. Go through to edit it to see the full result.

And jslint.com is happy with the code being used too.

1 Like

thank u :slight_smile: I also tried this way but if you look at other condition then it actually does not give the appropriate value.

when speed limit is 10-60, excess speed of 15 km/h leads to 85 euro fine but when limit is 70-120, same number of excess speed leads 70 euro fine.

but based on the condition u mention if i put driving speed 100 and limit 90, result will be 85 euro fine but i actually want to show 70 euro because now speed limit is higher. I am sorry if i do not make u understand

thank u bro…yes i know that how important it is to use appropriate variable names but still i am using this. i will inculde the right variable next time

What should the values be?

        var penalties = {
            "60": {
                "1-15": "85-euro",
                "15-20": "115-euro",
                "more": "unit fines"
            },
            "120": {
                "1-15": "70-euro",
                "15-20": "100-euro",
                "more": "unit fines"
            }
        };

the problem i am having with is that when speed limit is 10-60 km/h, excess speed of 15 km/h leads to 85 euro fine but when limit is 70-120, same number of excess speed leads 70 euro fine.

My condition just give 85 euro fine when its less than excess speed of 15km/h no matter how many kilometers i put as speed limit.

[quote=“draganlimon, post:14, topic:221277, full:true”]
the problem i am having with is that when speed limit is 10-60 km/h, excess speed of 15 km/h leads to 85 euro fine but when limit is 70-120, same number of excess speed leads 70 euro fine.[/quote]

Isn’t that what you said right at the top in your original post? I’ll quote it below:

yes, it is

sorry guys…i think i should study more… and thanks paul …

1 Like

I think that the fine difference can be rationalised.

When you are in a 60 limit area, pedestrians tend to be closer to traffic and result in a greater danger. Also the 15 km/h is a whole 25% faster than the 60 limit.

When on a 120 limit motorway, going 15 faster is only 12.5% faster than the 120 limit, so less of a penalty.

Hi paul, the way u solved the problem on jslint.com seems still has a problem. can you see my original post where all the condition has written? My program needs a driving speed and speed limit box as input type. In your solution i do not have option to put speed limit rather i just can select them 10-60 and 70-120 so the problem it has if i put driving speed 90, output shows no penalty because limit is 70-120 but i actually need two input one driving speed and one speed limit in order to get the output correct. for example in driving speed box if i put value 90 and speed limit 75, i will get 75 euro infraction fine. I am attaching some screenshot of the program.

How do the fines change depending on the speed limit?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.