472,334 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Javascript program to prompt and accept input from user

8
I'm having huge difficulties producing a script for this:
Write a javascript programme that will prompt for, and accept from the user, an input string which contains at least 8 characters. It should then prompt for and accept a numerical value that is no greater than the length of the input string and should output a version of the input string which takes the form of a string of the same length as the input string but consisting entirely of the letter which occurs in the input string at the position specified by the input number.

Been trying for days and just can't get it!!! :(((
Mar 9 '06 #1
8 12179
Banfa
9,065 Expert Mod 8TB
If you post the code of what you have so far we will try to help you, but since this sounds to me like a homework question I'm not just doing it for you.

BTW this would be better off in the Programming or Web Design forum.
Mar 9 '06 #2
lisaj
8
If you post the code of what you have so far we will try to help you, but since this sounds to me like a homework question I'm not just doing it for you.

BTW this would be better off in the Programming or Web Design forum.
<HTML>
<HEAD>
<TITLE>
Programme to accept no less than 8 characters
</TITLE>
<SCRIPT LANGUAGE = "JavaScript">

function getStringInput(){

myString = window.prompt('Enter a Word with more than 8 Characters Please!','');
if(!myString){
return
}

if (myString.length < 8)
{
alert("Please re-enter a Word with more than 8 Characters !") // tempory alert
getStringInput()
return
}

alert("Now enter a number that is smaller than the amount of letters in your inputed word" ) // tempory alert

getNumber()
}
function getNumber()
{
myNumber = window.prompt('Enter Your Number !','');
if(!myNumber){
return
}

if (count.myNumber > mystring.length)

window.prompt('The Number must be smaller than you inputed letters in Your word');
showResults()
}

function showResults(){

}

</script>

</HEAD>
<BODY onload="getStringInput()">

<div id="display"></div>

</BODY>
</HTML>
This is what i've done so far.....
Mar 9 '06 #3
lisaj
8
I'm having huge difficulties producing a script for this:
Write a javascript programme that will prompt for, and accept from the user, an input string which contains at least 8 characters. It should then prompt for and accept a numerical value that is no greater than the length of the input string and should output a version of the input string which takes the form of a string of the same length as the input string but consisting entirely of the letter which occurs in the input string at the position specified by the input number.

Been trying for days and just can't get it!!! ((

this is what i have so far.....
[HTML]<HTML>
<HEAD>
<TITLE>
Programme to accept no less than 8 characters
</TITLE>
<SCRIPT LANGUAGE = "JavaScript">

function getStringInput(){

myString = window.prompt('Enter a Word with more than 8 Characters Please!','');
if(!myString){
return
}

if (myString.length < 8)
{
alert("Please re-enter a Word with more than 8 Characters !") // tempory alert
getStringInput()
return
}

alert("Now enter a number that is smaller than the amount of letters in your inputed word" ) // tempory alert

getNumber()
}
function getNumber()
{
myNumber = window.prompt('Enter Your Number !','');
if(!myNumber){
return
}

if (count.myNumber > mystring.length)

window.prompt('The Number must be smaller than you inputed letters in Your word');
showResults()
}

function showResults(){

}

</script>

</HEAD>
<BODY onload="getStringInput()">

<div id="display"></div>

</BODY>
</HTML>[/HTML]
Mar 9 '06 #4
lisaj
8
<HTML>
<HEAD>
<TITLE>Program_TMA03
</TITLE>
<SCRIPT >

/* Program to read in a known number of data items and store them in an array */

var attendArray = new Array (5);
var dayArray = ['Monday','Tuesday','Wednesday','Thursday','Friday']


document.write('Array program to read in a known number of data items');
for (var day = 0; day < attendArray.length; day = day + 1)
{
attendArray[day] = window.prompt('Enter attendance value for ' + (dayArray + 1),'')
};
document.write('<BR>' + '<BR>');
document.write('Confirmation of data input' + '<BR>' + '<BR>');

for (var day = 0; day < attendArray.length; day = day + 1)
{
document.write(dayArray[day] + ' : ' + attendArray[day] + '<BR>')
}

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

When I execute this programme I need the value button to have the day on;
eg; Enter the attendace for Monday
Next: Enter the attendance for Tuesday

I can only seem to get it to write up all of the days of the week at once. Can anyone tell me why?

Hopefully waiting....
Mar 9 '06 #5
Banfa
9,065 Expert Mod 8TB
OK the problem you have is the order that you have declared your functions. In Javascript you need to have declared a function before you try to call it. You declare the functions in the order

getStringInput
getNumber
showResults

but getStringInput calls getNumber and getNumber calls showResults. You need to delare them in the order

showResults
getNumber
getStringInput

This is the sort of feature you often get in an interpreted (as opposed to compiled) language.

On the contents of the function getStringInput, the recursive calling works but in this case since it could be replaced with a simple do ... while loop. In pseudo code this would look something like

Expand|Select|Wrap|Line Numbers
  1.   do
  2.   {
  3.     string = GetInputFromUser;
  4.  
  5.     if ( string.length <= 8 )
  6.     {
  7.       Display Error Message;
  8.     }
  9.   } while( string.length <= 8 );
  10.  
Just in case you are wonder psudo code is code that shows the structure of what needs to be done without neccessaryily being runnable code of a given language.

1 final note, the question calls for a string of at least 8 characters and the logic you have code tests for a string of at least 8 characters but your error messages says

"... more than 8 Characters ..."
Mar 9 '06 #6
Banfa
9,065 Expert Mod 8TB
When you say the value button I assume you mean window prompt box.

attendArray[day] = window.prompt('Enter attendance value for ' + (dayArray + 1),'')

should be

attendArray[day] = window.prompt('Enter attendance value for ' + dayArray[day]);

Make sure you understand why.
Mar 9 '06 #7
lisaj
8
When you say the value button I assume you mean window prompt box.

attendArray[day] = window.prompt('Enter attendance value for ' + (dayArray + 1),'')

should be

attendArray[day] = window.prompt('Enter attendance value for ' + dayArray[day]);

Make sure you understand why.
You are an absolute star ***** many thanks x
Mar 9 '06 #8
m3rajk
8
i really dislike doing other people's homework. but since you have tried, i will give you this clue:
you need 4 variables:
var input_string
var output_string
var is_length
var is_place

you should use onChange() to update your length

in psuedo-code:

Expand|Select|Wrap|Line Numbers
  1. <html start stuff>
  2. <script language="javascript">
  3.  
  4. // declare variables
  5.  
  6. function valid(){
  7.   if (length<8){
  8.     alert("you must have 8 or more characters");
  9.     return FALSE;
  10.   }else{
  11.     alert("thank you for entering 8 or more characters");
  12.     return TRUE;
  13.   }
  14. }
  15.  
  16. function getPlace(){
  17.   while(place is not between 0 and length){
  18.     place=window.prompt("enter a number 0 to length");
  19.   }
  20. }
  21.  
  22.  
that shouyld be a good starter
Mar 9 '06 #9

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

Similar topics

5
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like...
2
by: atreide_son | last post by:
hello all... yes i'm a newbie and i need help. i have an assignment due for class, but I don't know i'm stuck and can't get out from under...
3
by: J.P. Cummins | last post by:
In my ASP.NET application, I wish to have a page for administrators to edit items in a list. Preferably, I would like to use the javascript prompt...
0
by: joestevens232 | last post by:
I am seriously stuck and have been working on this for hours and hours and can't figure out my next step....heres the program assignment. This...
10
by: ycg0771 | last post by:
I'm trying to modify the following program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of ...
6
by: ahin | last post by:
can any one help or give an idea about writing or from where to strat the following program? • Load a list of available courses from a text file...
2
by: steve | last post by:
Hi guys, I have a problem with the Safari browser. specifically the following javascript will not print any headings until after the JS has...
6
by: aureao4 | last post by:
I'm new to Java and programming. I'm trying to code a payroll program and continue getting errors. The program worked last week, this week I have to...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.