473,395 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Determine position of letter by inserting number, output letter

2
Hi,

Please could someone shed some light on this as I am really struggling to understand how to do this.

Given a word entered into a window.prompt EG "forum", how do I create a script to determine the postion of a letter by entering a number no longer than the string and output that letter to screen.

I have completed the prompting and selection the bold section below is where I become stuck. Any help would be appreciated greatly.
EG

prompt - enter a word no more than 5 characters

user submit "forum"

prompt - select a number from 1 to 5

user submit "2"

write - your chosen letter is o



Regards,

Gazz
Jun 5 '07 #1
2 1560
iam_clint
1,208 Expert 1GB
this was an easy one so i wrote a pretty good example up for you. please respond with anything you don't understand in this script and i will explain it further.
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. window.onload = getLetter();
  3. function getLetter() {
  4. var resp = "";
  5. resp = window.prompt("type in a 5 letter word", "");
  6. if (resp.length!=5) { alert("You did not type in a 5 letter word!"); getLetter(); return false; }
  7. var num = 0;
  8. num = window.prompt("Select a number 1-5", "");
  9. num = parseFloat(num);
  10. if (num>0 && num<6) { document.write("Your chosen letter is " + resp.charAt(num-1)); } else { alert("That is not a number 1-5"); getLetter(); return false; }
  11. return true;
  12. }
  13. </script>
  14.  
Jun 5 '07 #2
gazz
2
Hi Thanks iam_clint,

Greatly appreciate your help.

Strange how once you see something work you realise how it should have been done.

Once again thanks.

Gary
Jun 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
0
by: Anna | last post by:
Hi all. I have a rather short question: How can I in xsl to get a letter, given its position in the alphabet, e.g. given number 5, return a letter 'e'? Is it possible in pure xsl or do I need to...
7
by: Andrew | last post by:
Hello, Is it possible for a file position indicator of an input stream to be greater than the size of a file? And if so could this cause fgetc to somehow write to the file? For example is it...
9
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2:...
8
by: Jeff | last post by:
Ok gang, I am going to try and explain my question. I have a page where a person's position is listed. This is what I am using to get that position. I first sort by the round field in the DB,...
13
by: CJM | last post by:
I have an ASP/ADO application querying an SQL Server DB. I want know the most efficient way to determine if more than one row is returned from a query. If more than one row is returned, the user...
9
by: Ulterior | last post by:
Hi, everyone, I have a simple problem, which bothers me for some while. I will try to explain it - There is some string, whith different letters in it. Is it possible to analyse this string...
2
by: Eraser | last post by:
Hello, I'm just starting to learn PL/SQL. To get my feet wet, I'm trying to write a simple stored procedure that takes some values as parameters, and inserts those values into a table. For...
4
by: sarika | last post by:
Hi all I want to create an online stamp making site. In my site a user select a template from number of templates for making his stamp. The template is and image with some graphics and text. Now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.