Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-05-2011, 02:12 PM   PM User | #1
university
New Coder

 
Join Date: Jul 2011
Posts: 18
Thanks: 2
Thanked 0 Times in 0 Posts
university has a little shameless behaviour in the past
writing javascript functions and event handler??

Q1. write a function called countAS that will take a string as input (using a prompt dialog box,prompt the user or the string).the string must contain only a's,b's and c's e.g. "abccbbaa" or "aaabbbccc" if any other letters are present apart from the letters a b c, output an alert dialog box with an error message and prompt the user again to input a valid string.count the number of a's the numbers of b's and the numbers of c's entered and display the count for each as well as a total count of all the characters within the string .

for example if the string was abbcc output should be as follows:
the total count is 5 characters
The Number of a's is 1
The Number of b's is 2
The Number of c's is 2

Q2. write a code that uses an event handler to display an alert dialog box with the message 'hello to you all' when a user clicks a link in a html page which links to the school of computing website.
university is offline   Reply With Quote
Old 07-05-2011, 02:50 PM   PM User | #2
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
There's a few ways you can do this.

You could use a regular expression to first check if the string is valid. If it is, then loop through the string and count how many a b and c's you have. If it isn't the prompt the user for another string.

Another option is to not use a regular expression, but loop through the string using charAt(). At each character use a switch() block to count the a b and c letters and if the char is not a valid character reset the a b c counters to 0 and prompt the user for another string.

Post the code you have so far and we can try to help you get it working.
bullant is offline   Reply With Quote
Old 07-05-2011, 03:40 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Blatant homework!

See http://www.codingforums.com/showthread.php?t=221359 Post #5
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 07-05-2011, 11:22 PM   PM User | #4
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
yep, probably is homework.

But if the op doesn't get any help here, they most probably will on another website.

I don't have any issues helping people with queries (whether it is homework or not) if I see they are making a genuine effort to do it themselves first

Last edited by bullant; 07-05-2011 at 11:24 PM..
bullant is offline   Reply With Quote
Old 07-06-2011, 06:15 PM   PM User | #5
university
New Coder

 
Join Date: Jul 2011
Posts: 18
Thanks: 2
Thanked 0 Times in 0 Posts
university has a little shameless behaviour in the past
Quote:
Originally Posted by Philip M View Post
its not homework im trying out a bunch of qusetions and because im new at this sort of stuff i am finding it hard to understand and yes i have read all the rules and stuff but if this website is not for helping others than why even have it.i was just looking for some help and so i thought this was the right place to ask any questions or problems that i am having.
university is offline   Reply With Quote
Old 07-06-2011, 07:46 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
The answer is the same as before. If you show us the code you yourself have written we will be happy to correct or improve it, but you must make a genuine effort yourself.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 08-03-2011, 06:11 PM   PM User | #7
university
New Coder

 
Join Date: Jul 2011
Posts: 18
Thanks: 2
Thanked 0 Times in 0 Posts
university has a little shameless behaviour in the past
Quote:
Originally Posted by Philip M View Post
The answer is the same as before. If you show us the code you yourself have written we will be happy to correct or improve it, but you must make a genuine effort yourself.
so is this right for the second question?

<a href='schoolofcomputing.com' onclick='alert("Hello to you all")'>Link</a>
university is offline   Reply With Quote
Old 08-03-2011, 07:01 PM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Try it - don't ask us!

<a href='http://schoolofcomputing.com' onclick='alert("Hello to you all")'>Link</a>
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 Jump


All times are GMT +1. The time now is 03:13 AM.


Advertisement
Log in to turn off these ads.