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 Equations calculator - help

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 01-09-2013, 04:19 PM PM User | #1 Potices New to the CF scene   Join Date: Jan 2013 Posts: 3 Thanks: 0 Thanked 0 Times in 0 Posts Equations calculator - help Hey guys. I'm working on a program that can calculate your equations. I'm not finish yet but as you can see here, I want it to print out the 'c' variable and the 'b' variable via an alert. So what's wrong with it? Later I will make css and finish the code... Code: ```HTML: ``` ---------------------------------------------- Javascript: Code: ```var ligning = prompt("Indtast din ligning her:"); var calculator = function() { for(i = 0; j=true; i++) { var k = i; var a = ligning.substring(k,1+k); if (a === "=") { j = false; var b = ligning.substring(0, i); var c = ligning.substring(i+1, 200); alert("end.") } else {j=true;} } }; alert(ligning); alert(c); alert(b);``` Last edited by Potices; 01-09-2013 at 05:10 PM..
 01-09-2013, 04:55 PM PM User | #2 WolfShade Regular Coder   Join Date: Apr 2012 Location: St. Louis, MO, USA Posts: 966 Thanks: 7 Thanked 100 Times in 100 Posts You are closing the for loop before anything else is processed, so it will run indefinitely, as j will always be true. __________________ ^_^ If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link. * The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
 01-09-2013, 05:09 PM PM User | #3 Potices New to the CF scene   Join Date: Jan 2013 Posts: 3 Thanks: 0 Thanked 0 Times in 0 Posts Oh your right. I changed it, but It still doesn't work at all. I updated the thread, so the 'new' code is at the very top. I did also add a new alert. In the event; 'if (a === "=")' I added the alert 'end' just so I could see if it could find the "=". But it couldn't, so my question is why, and how can I fix it?
 01-09-2013, 05:10 PM PM User | #4 007julien Regular Coder   Join Date: May 2012 Location: France Posts: 174 Thanks: 0 Thanked 27 Times in 25 Posts A simpler variant : Code: ```var k=0; while (ligning.substring(k) && ligning.substring(k,k+1)!=='=') k++; if (ligning.substring(k,k+1)==='=') {// We find the sign = var b = ligning.substring(0,k); var c = ligning.substring(k+1, 200); } else alert('This entry is not an equation');``` But, an other sign = is possible in c !!! Incidentally, there is no need to make a loop to find and cut a string on a sign = Code: `var arrEqt = ligning.split('='); // give immediately arrEqt[0] and arrEqt[1] if the length of arrEqt is two !` Please use the Go Advanced and Code buttons... Last edited by 007julien; 01-09-2013 at 05:25 PM.. Reason: complement
 01-09-2013, 06:22 PM PM User | #5 Potices New to the CF scene   Join Date: Jan 2013 Posts: 3 Thanks: 0 Thanked 0 Times in 0 Posts Thank you very much 007julien! I'm new at Javascript and I will use the .split method instead. Thank you very much!

 Bookmarks

 Tags calculator, equation

 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 01:23 AM.