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 Problem Cycle FOR

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 11-09-2012, 05:37 PM PM User | #1 triko New Coder   Join Date: Oct 2012 Location: Italy Posts: 72 Thanks: 3 Thanked 0 Times in 0 Posts Problem Cycle FOR This program Calculate the TAX CODE! If the name have less than 3 consonants, is insert the first vocal at the end of 2 consonants; EXAMPLE: 1° case LUCA ==> L, C, U ANNE ==> N, N, A BELA ==> B, L, E If the name have more of 3 consonants, I take first, and second jump, and I take third and fourth consonants EX: 2° case ALEXANDER ==> L, N, D JONATHAN ==> J, T, H SANDRO ==> S, D, R 3° case If the name have less to 3 letters, I add X at the end of word RA ==> RAX AS ==> ASX Ok now that i have explained how to work Tax Code, I have a problem; I don't know how to count the consonants in the name EX: LUCA, for insert the "U" at the end of consonants!!! I say " It's possible insert a VARiable = 0 into the cycle FOR that increases with each consonants, that at the end I have a VAR with a value < 3 or > 3, for continue and create 1°, 2°, and 3° case???" Thanks you all for your Time and Attention This is code Code: ``` function calculateName(name) { var myName = ""; for (var i = 0; i < name.length; i++) { var count = 0; if ( (name[i] != "a") && (name[i] != "e") && (name[i] != "i") && (name[i] != "o") && (name[i] != "u") ) { var myName; myName = myName + name[i]; myName = myName.substring (0,3); count ++; } } alert (myName); alert (count); }```
 11-09-2012, 10:08 PM PM User | #2 felgall Master Coder     Join Date: Sep 2005 Location: Sydney, Australia Posts: 6,081 Thanks: 0 Thanked 578 Times in 568 Posts You can get the number you want with a single JavaScript statement (assuming that you have already checked that the name only contains letters). Code: `consonants = name.replace(/[aeiou]/ig,'').length;` There is no need to use a loop for something so simple. Of course if this is for a history of JavaScript course then you wouldn't be able to use that solution because the historic version of JavaScript you are learning to use in old versions of the Netscape browser will not cover that. __________________ Stephen Learn Modern JavaScript - http://javascriptexample.net/ Helping others to solve their computer problem at http://www.felgall.com/
 11-09-2012, 10:16 PM PM User | #3 Old Pedant Supreme Master coder!     Join Date: Feb 2009 Posts: 24,941 Thanks: 75 Thanked 4,306 Times in 4,273 Posts This is the same homework that generated a bunch of responses about a week ago. You are the 3rd person to come here asking us to do your homework. The first person sneakily concealed the fact it was homework. But I will tell you that you have the line Code: ` var count = 0;` in the wrong place. It needs to be *before* the for( ) statement. __________________ An optimist sees the glass as half full. A pessimist sees the glass as half empty. A realist drinks it no matter how much there is.
11-10-2012, 01:02 AM   PM User | #4
triko
New Coder

Join Date: Oct 2012
Location: Italy
Posts: 72
Thanks: 3
Thanked 0 Times in 0 Posts
Quote:
 Originally Posted by Old Pedant This is the same homework that generated a bunch of responses about a week ago. You are the 3rd person to come here asking us to do your homework. The first person sneakily concealed the fact it was homework. But I will tell you that you have the line Code: ` var count = 0;` in the wrong place. It needs to be *before* the for( ) statement.
o.O o.O o.O
Pedant, but..... How did you do???
I stay 2 hour... But don t find the solution... You arrive and write, before the for() statement, and solve my problem..... You are a genius.. And i'm stupid, maybe this isn't my subject... I don't understand and don't find the solution!!!
So, Thank you

 11-10-2012, 01:55 AM PM User | #5 felgall Master Coder     Join Date: Sep 2005 Location: Sydney, Australia Posts: 6,081 Thanks: 0 Thanked 578 Times in 568 Posts There are two factors that make the difference. 1. You are not very familiar with JavaScript and so do not know how you would expect the script to look or what sots of things to look for that commonly use problems. Old Pedant is very familiar with JavaScript and so is far more likely to spot errors. 2. You wrote the code so you know exactly what it is supposed to do so in looking at the code you easily overlook small errors because you read that piece of code the way you expect it to work rather than as how it actually will work. That's why even stopping to explain the problem to someone else often leads to the solution as you start looking at the code in a different way. There are two things you can do to make finding errors in your JavaScript easier. First make use of http://jslint.com/ to check your JavaScript syntax - simply paste your script into that page and check the "assume a browser" checkbox and it will give you a list of everything you need to change to fix all the syntax errors as well as a lot of the code that is potentially going to cause errors. Second, all browsers except Firefox have a JavaScript debugger built in that you can use to step through your code and see exactly what each statement does (you can install an debugger as a Firefox extension if you need to debug in that browser). __________________ Stephen Learn Modern JavaScript - http://javascriptexample.net/ Helping others to solve their computer problem at http://www.felgall.com/

 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 06:41 AM.