Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Brick Wall Calculator Nan??

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 07-02-2012, 02:46 AM PM User | #1 Blowpipe New Coder   Join Date: Dec 2011 Posts: 15 Thanks: 1 Thanked 0 Times in 0 Posts Brick Wall Calculator Nan?? Hi there, Right hopefully I have managed to post this time in the correct forum page!! Sorry to the Admins for my previous posting errors I am working on a algerba to JS formula conversion for a calculator and need some help as I am currently getting NaN with the code below. Pretty much it is to work out area of a brick wall minus a round window and the associated costs. I know my algebra is on the money, just need some assistance in the coding conversion. Thanks for taking a look. BP ``` Brick Wall Cost Calc

Cost of Brickwall with a Round Glass Window

Cost of wall

```
07-02-2012, 03:08 AM   PM User | #2
Logic Ali
Senior Coder

Join Date: Sep 2010
Location: London
Posts: 1,027
Thanks: 0
Thanked 206 Times in 201 Posts
Quote:
 `onClick="calculate(l, h, d)`
l, h & d are undefined variables.

07-02-2012, 03:27 AM   PM User | #3
Blowpipe
New Coder

Join Date: Dec 2011
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts

Quote:
 Originally Posted by Logic Ali l, h & d are undefined variables.
Hi Ali,

Thanks for taking a look.

How do you mean I haven't declared them? They are part of the parameters of the function and are user dependant values.

Below is what I came up with on paper, I just don't know how to integrate it into my code properly.

// x is the cost per sqm for brick
var x = 30;
//y is the cost per sqm for glass
var y = 20;

// ’h’ = height of wall, ‘l’ = length of wall and ‘d’ diameter of the round window
var costBrickWall = function (l, h, d) {

//Math.PI will return a value of 3.141592653589793, for a more exact value use 3.14
//window = Area of Circle this function is using pi diameter square divided by 4
var window = Math.PI * Math.pow(d,2)/4;
return x * ((l * h) - window) + y * window;
};
//call the function
costBrickWall(l, h, d);

 07-02-2012, 06:03 AM PM User | #4 xelawho Senior Coder     Join Date: Nov 2010 Posts: 2,591 Thanks: 54 Thanked 477 Times in 475 Posts you don't need to pass those values to the function in the onclick but you do need to reference them correctly (and as long as x and y are only used by one function you may as well keep them local. one other thing - "window" is a javascript keyword. you can get away with using it, but it's better off avoided: Code: ``` ```
 Users who have thanked xelawho for this post: Blowpipe (07-02-2012)
 07-02-2012, 11:56 AM PM User | #5 Blowpipe New Coder   Join Date: Dec 2011 Posts: 15 Thanks: 1 Thanked 0 Times in 0 Posts Hi Xelawho, Thanks for the heads up about the "window" keyword, I wasn't aware of that one. And thanks for taking a look at what I had and helping me to improve my coding Cheers BP
 07-02-2012, 12:10 PM PM User | #6 Blowpipe New Coder   Join Date: Dec 2011 Posts: 15 Thanks: 1 Thanked 0 Times in 0 Posts A big thanks to everyone who had a look at what I had and helped me with it. It is good to know that I wasn't that far off actually having the correct code, and that I need to remember "declare all variables". Cheers BP

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 10:38 PM.