<!--
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;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.