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!!! :(((
8 12274 Banfa 9,065
Recognized Expert Moderator Expert
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.
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.lengt h < 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="getStri ngInput()">
<div id="display"></div>
</BODY>
</HTML>
This is what i've done so far.....
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.lengt h < 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="getStri ngInput()">
<div id="display"></div>
</BODY>
</HTML>[/HTML]
<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','Tuesd ay','Wednesday' ,'Thursday','Fr iday']
document.write( 'Array program to read in a known number of data items');
for (var day = 0; day < attendArray.len gth; 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.len gth; 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....
Banfa 9,065
Recognized Expert Moderator Expert
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 -
do
-
{
-
string = GetInputFromUser;
-
-
if ( string.length <= 8 )
-
{
-
Display Error Message;
-
}
-
} while( string.length <= 8 );
-
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 ..."
Banfa 9,065
Recognized Expert Moderator Expert
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.
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
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: -
<html start stuff>
-
<script language="javascript">
-
-
// declare variables
-
-
function valid(){
-
if (length<8){
-
alert("you must have 8 or more characters");
-
return FALSE;
-
}else{
-
alert("thank you for entering 8 or more characters");
-
return TRUE;
-
}
-
}
-
-
function getPlace(){
-
while(place is not between 0 and length){
-
place=window.prompt("enter a number 0 to length");
-
}
-
}
-
-
that shouyld be a good starter
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 to get the Buttons to correspond with the action to
either a) generate numbers b) Prompts a user to locate a web page c)
go to previous page in history list d) Loads next page in history list
e)...
|
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 myself.
here's the focus of the program:
Write a C program that allows the user to make some simple banking
|
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 for the 'rename' function, and a javascript alert box for the
'delete' function. When the user clicks 'rename', the javascript prompt
asks for the new name. When the user clicks 'delete', a...
|
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 vending machine dispenses 1. M&Ms ($.65), 2. Chips ($1.16), 3. Peppermint gum ($.28). Your
program should prompt the user to deposit money (i.e. the user needs to type in the amount deposited at
the...
|
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
hours worked. Use a constructor to initialize the employee information,
and a method within that class to calculate the weekly pay. It seems that the more I read into this, the more confused I get....
| |
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 into an array (max 4 courses).
File format can be like this:
C310211
Programming II
700
C310453
|
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 executed.
<script type = "text/javascript">
|
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 add set, get and a class. I've written the class but when I compile the program I get 13 errors. Can anyone assist me with this? Thank you!
Errors I get:
C:\Java>javac *.java
Payroll3.java:18:...
|
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 product, the number of
units in stock, the price of each unit, and the value of the inventory of that product. In
addition, the GUI should display the value of the entire inventory, the additional...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |