2. Bangalore Traffic

by venkatavineela

HTML

<!--
Problem 2:

Background:
Bangalore has heavy traffic. One common cause is slow-moving vehicles using the same lanes as fast-moving vehicles. Auto rickshaws form a majority of these slow-moving vehicles.
http://bit.ly/oz3969

Problem statement:
The Indian government traffic jam analysis department has done some research and has found that traffic jams will occur when the number of auto rickshaws on the road is more than 40. Unless it is after 8pm in which case there are no traffic jams because the daytime traffic has finished. 

Examples:
Given there are 30 auto rickshaws in the road
And the time is 3pm
When the traffic jam system is queried 
Then no traffic jam is predicted

Given there are 41 auto rickshaws in the road
And the time is 3pm
When the traffic jam system is queried
Then a traffic jam is predicted

Given there are 60 auto rickshaws in the road
And the time is 10pm
When the traffic jam system is queried
Then no traffic jam is predicted

-->

<html>
    <body>
        <div>The Answer is: </div>
       No of autorickshaws: <input type="text" name="autorick" id="number"/><br/>
       Time: <input type="text" name="time" id="tim"/><br/>
       <button id="butclk">
       Check traffic</button><br/>
       </button>
        <span id="answer"></span>
    </body>
</html>

JavaScript

document.getElementById("butclk").onclick= isTrafficJam;
function isTrafficJam(numberOfAutoRickshaws, isAfterEightPm) {
    numberOfAutoRickshaws=document.getElementById("number").value;
var timeIn=parseInt(document.getElementById("tim").value);
if(timeIn >8)
{
 isAfterEightPm=true;
}
else
{
 isAfterEightPm=false;
}
    var answer=" ";
    if((isAfterEightPm==true)||(numberOfAutoRickshaws<40))
    {
    answer="Then no traffic jam is predicted";
    }
    if((isAfterEightPm==false)&&(numberOfAutoRickshaws>40))
    {
    answer="Then a traffic jam is predicted";
    }
    
    
   document.getElementById("answer").innerHTML=answer;
    
    
}