HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

Airflow calculator

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
airflowcalculatorstackoverflow

Problem

I have started to learn JavaScript over the last few weeks. I have gone through most of the Head First JavaScript Programming book and it has been fantastic. I highly recommend it!

Anyways, I found a cool little project that I wanted to attempt to make a script for. After a few hours of learning, adding and bug squashing, I have a working script.


Airflow Calculator:


Test Values:


Area: 150


Ceiling Height: 2.7


Adjustment Factor: 1


Unit: D095





//Air Changes Calculator

function init() {
// Set the User Variables
var unit = ["D095", "D125", "D160", "D195", "D230", "D255", "C125", "C160", "C205", "C240"];
var m3 = [7500, 10000, 12500, 15000, 18000, 19500, 10000, 12500, 16000, 18500];

var webPrint = document.getElementById("output");
var reccommended = document.getElementById("reccommended");

var floorArea = document.getElementById("floorarea").value;
var ceilingHeight = document.getElementById("ceilingheight").value;
var adjustmentFactor = document.getElementById("adjustment").value;
var unitAir;

var volume = floorArea * ceilingHeight;
var adjustedVolume = volume * adjustmentFactor;
var unitSelection = document.getElementById("model").value;

for (var i = 0; i 30 && suggestResult 30 && suggestResult

Enter Floor Area:
Enter Ceiling Height:
Enter Adjustment Factor (Min 1):
Enter Unit Model:

Recommended Units:






Can I make this any simpler? Is there anything I have missed or gone a long way around with?

Advancing from here, how can I have the values in an object, and then look-up the object as per my current script? Is this possible or do I need an array for both 'Unit' and 'M3'?

My next step after that would be to have it connect to an XML or JSON document and retrieve the values from there and also to have error checking on each field.

Solution

The misspelling of reccommended is a trap for future maintenance. (You spelled it correctly in the `.)

The HTML fails to validate. It is a good idea to run your HTML through a validator, which would have told you that

  • The is missing a tag.



  • There is no such thing as a tag — you probably meant


, but
would have sufficed.

It is not clear what measurements you expect. Metres? Feet? Feet and inches? (If so, will it accept
8 ft 2 in or 8'2" or some other format?) Putting "m2" after the text box would have eliminated this usability problem. (Use the tag.)

The "Enter Unit Model" input should clearly be a drop-down selection instead of free-form text.

Since you are using HTML 5, you should use
. This gives a better user experience, particularly with Android, which will display a numeric keypad. (iOS is less helpful: is only shows a numeric keypad if you specify integer-only inputs using pattern="\d*".)

init() is not the right name for your function. showRecommendations()` would be better.

Context

StackExchange Code Review Q#69337, answer score: 5

Revisions (0)

No revisions yet.