Re: js Newbie
From: Steve van Dongen [MSFT] (stevevd_at_online.microsoft.com)
Date: 07/18/04
- Next message: Lee: "Re: dropdown box, checkbox validation"
- Previous message: Dr John Stockton: "Re: Bug: Parsing float 1e20 with decimal point"
- In reply to: ilir hoti: "Re: js Newbie"
- Next in thread: ilir hoti: "Re: js Newbie"
- Reply: ilir hoti: "Re: js Newbie"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 17 Jul 2004 17:16:33 -0700
On Sat, 17 Jul 2004 18:43:20 GMT, ilir hoti <ihoti2001@ntlworld.com>
wrote:
>Lee wrote:
>
>> ilir hoti said:
>>
>>>Hi guys
>>>having great difficulty with figuring out the dropVowels functionneed
>>>some urgent help, please, thanks in advance.
>>>here is my code
>>
>>>any suggestions would be greatly anticipated,
>>
>> I suggest you drop the class.
Altough in the end it may in fact turn out to be a good suggestion,
lets not be hasty. :)
>OK first of all I guess you are pretty good at JS, yes you are absolutly
>right i did copy some of the code.
>But I would appreciate if you could give me some help instead of having
>a go. No doubt that you were once a complete novice, unless you were
>born with the talent of programming. And as such you will appreciate
>that i am finding it very difficult to come up with an answer to this
>particular question. so i made the effort for a good few hours today and
>wrote my own code. Here it goes:
You will find that most people can fairly easily spot homework-style
problems, having also done them at some point in their lives, and will
generally opt to either ignore the post completely or will offer hints
rather than simply providing a complete, working solution.
Ironically, if this is indeed a homework question, it's a really bad
one considering you can delete all the vowels with one built-in
function call.
Anyways...
>function dropVowel(aCharacter)
>{
>var aCharacter = vowelString['a','A','e','E','i','I','o','O','u','U']
>}
Here there is a funtion that is presumably the function that you are
asking for help writing, yet it is never called and effectively does
nothing. All it does is create and (incorrectly) initialize a local
variable.
>var resultString='';
>var inputString = window.prompt('enter your string here', '');
>var vowelString= ['a','e','i','o','u','A','E','I','O','U'];
>var position='';
>{
>for (var position=0; position<resultString; resultString=position+1);
for statement
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsstmfor.asp
Consider what this loop does...
1. Initialize position=0
2. Compare position ( 0 ) < resultString ( '' ). What is the logical
result of testing whether 0 is less than an empty string?
3. Assuming the above test evaluates to false, resultString is set to
position+1 ( 1 )
4. Note that your for statement ends in a ; meaning that there are no
statements executed on each loop iteration.
>}
>if (inputString!=vowelString)
>{
>document.write(inputString != vowelString + '<BR>'+ resultString)
>}
>I know this is so wrong, but could you point out where i am going wrong.
Where you are going wrong is not first thinking about what you are
trying to accompish. You have to think about the problem and break
the it up into smaller pieces. People who cannot think about and
understand the problem cannot write a program to solve it.
When I interview people, I am primarily looking for problem solvers.
If you happen to be write code proficiently in the languages we use,
great, but if not then I don't kick you out the door and there is
still a chance you will get hired. Good programmers can learn new
languages without much difficulty. Learing problem solving and the
thinking processes involved *before* writing code is much more
difficult. In fact I have heard some people claim that these skills
actually cannot be taught -- that it comes naturally to people who
turn out to be good programmers.
First, define the problem. You never really said what you are trying
to do, but I deduce that the problem is --
Delete all the vowels from a string.
Then think about how you do that --
Check whether each character is a vowel, and if it is, delete it.
Then start writing psuedo-code for the logic --
prompt for a string
loop through each character in the string
if the current character is a vowel...
delete the current character from the string
display the result
At this point, you might look at the psuedo-code above and think, "How
do I know if the current character is a vowel?" followed by "That
would probably be a good thing to have a function for". Then you
would start writing psuedo code for that --
function IsVowel ( takes a character as an input parameter)
if the character is a, e, i, o, or u then it is a vowel
otherwise it is not
Now, the entire problem is solved. Up until this point you have
simply been planning and thinking about what you are trying to
accomplish. As you start to write the program you will have to start
thinking about language-specific details. For example, lets say you
were writing the code for this step --
delete the current character from the string
If you were writing the code in C++ you would likely not literally
"delete a character from the string". Instead, you would loop through
the string, copying non-vowel characters overtop of vowel characters,
and then terminate the string. Likewise, if you were implementing
this in JScript (which you are obviously), you would probably loop
through the string, copying non-vowel character overtop of vowel
characters, and then (because you cannot terminate a string like you
can in C++) copy the substring of characters you want to keep to a new
string.
Hopefully by now I've given you enough to think about.
JScript Fundamentals
http://msdn.microsoft.com/library/en-us/script56/html/js56jsconjscriptfundamentals.asp
Regards,
Steve
-- Please post questions to the newsgroup; everyone benefits. This posting is provided "AS IS" with no warranties, and confers no rights. Sample code subject to http://www.microsoft.com/info/cpyright.htm
- Next message: Lee: "Re: dropdown box, checkbox validation"
- Previous message: Dr John Stockton: "Re: Bug: Parsing float 1e20 with decimal point"
- In reply to: ilir hoti: "Re: js Newbie"
- Next in thread: ilir hoti: "Re: js Newbie"
- Reply: ilir hoti: "Re: js Newbie"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|