Script Categories













Calculators >>> Horsepower.

Enter your vehicle's quarter mile time (assuming you know it) and vehicle weight and this JavaScript program will display your car's estimated horsepower.

Horsepower Calculator
Car Model :
Vehicle Weight With Driver : (in Pounds)
Quarter Mile time : (in seconds)

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
var weight, eTime;
var horsepower1, horsepower2, horsepower3, horsepower4;
var temp1, temp2, temp3, temp4;
var speed;
var finalhp1, finalhp2, finalhp3, finalhp4, finalhp5, finalhp6;
function create(form){
eTime = form.elapsedTime.value;
weight = form.vehicleWeight.value;
temp1 = eTime / 5.825;
temp1 = temp1 * temp1 * temp1;
horsepower1 = weight / temp1;
finalhp1 = roundOff(horsepower1, 2)
horsepower2 = horsepower1 * 1.3;
finalhp2 = roundOff(horsepower2, 2)
text = "<HEAD><TITLE>1/4 Method</TITLE>";
text += "</HEAD><BODY BGCOLOR=#000000 TEXT=#FFFFFF>";
text += "<font face=arial size=-1><CENTER>";
text += "Horsepower Results - 1/4 Mile Method</CENTER><P>";
text += "Your " +form.carModel.value;
text += " weighs about " +form.vehicleWeight.value+ " pounds ";
text += "and can complete a 1/4 mile in about ";
text += form.elapsedTime.value;
text += " seconds. That means that you've got about " +finalhp1;
text += " HP at the wheels, and about " + finalhp2;
text += " HP at the flywheel.</font>";
text += "<center><form><input type=button onClick='self.close()' ";
text += "value='Close Window'></form></center></font>";
resultsWindow=window.open("", "displayWindow", "toolbar=no,menubar=no,scrollbar=auto,resizable=no,width=320,height=180")
resultsWindow.document.writeln(text);
resultsWindow.document.close();
}
function input1(form) {
Ctrl = form.carModel;
if (Ctrl.value == "") {
validatePrompt (Ctrl, "Please Input a Car Model.")
return (false);
}
else
return
(true);
}
function input2(form) {
Ctrl = form.vehicleWeight;
if (Ctrl.value == "") {
validatePrompt (Ctrl, "Please enter Your Vehicle Weight in Pounds.")
return (false);
}
else
return
(true);
}
function input3(form) {
Ctrl = form.elapsedTime;
if (Ctrl.value == "") {
validatePrompt (Ctrl, "Please enter Your 1/4 mile trapspeed. You can estimate...")
return (false);
}
else
return
(true);
}
function runSubmit (form, button)  {
if (!input1(form)) return;
if (!input2(form)) return;
if (!input3(form)) return;
create(form);      
return;
}
function validatePrompt (Ctrl, PromptStr) {
alert (PromptStr)
Ctrl.focus();
return;
}
function roundOff(value, precision) {
value = "" + value;
precision = parseInt(precision);
var whole = "" + Math.round(value * Math.pow(10, precision));
var decPoint = whole.length - precision;
if(decPoint != 0) {
result = whole.substring(0, decPoint);
result += ".";
result += whole.substring(decPoint, whole.length);
}
else {
result = whole;
}
return result;
}
// End -->
</script>
<b>Horsepower Calculator</b>
<form name="hp" method=get action="">
<table border=0>
<tr
bgcolor="#909090">
<td
align=right><font face="Arial, Helv"><b>Car Model : </b></font></td>
<td>
<INPUT TYPE=text NAME="carModel" SIZE=20></td>
<tr
bgcolor="#909090">
<td
align=right><font face="Arial, Helv"><b>Vehicle Weight With Driver : </b></font></td>
<td>
<INPUT TYPE=text NAME="vehicleWeight" SIZE=10> (in Pounds)</td>
<tr
bgcolor="#909090">
<td
align=right><font face="Arial, Helv"><b>Quarter Mile time : </b></font></td>
<td>
<INPUT TYPE=text NAME="elapsedTime" SIZE=10> (in seconds)</td>
</table>

</font>
<input type=button onClick="runSubmit(form)" name="HPcalc" value="Calculate Horsepower">
</form>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).

R7


©