/    Sign up×
Community /Pin to ProfileBookmark

help with display

could anyone point me in the right direction please. i have a small program to take a string input and then a number from the user and should then print on the screen a character from that string at the number postion the number of time of that number…if that makes sense… if i input qwertyuiop and the number 4 the display should read rrrr. so far i have the following to take the imput:
//get stringinput then check that it over 8 charaters//

mystring = window.prompt(‘enter a string of at least 8 characters’,”)
while (mystring.length <8)
{
mystring = window.prompt (“you must enter a string longer than 8 charaters”,”)
}

//get number//
anumber = window.prompt(“enter a number no larger than your string”,”)
//check length of number//
while (anumber>mystring.length)
(
anumber = window.prompt (“you must enter a number smaller than your string length”,”)
)
length = mystring.length
mystring = mystring.charAt(length)//

I can print out the length of the entered string but not the charAt(number) so that i can test the script is working up to that point.

cheers for any help you can give

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ExuroMar 11.2006 — The [FONT=Courier New]charAt()[/FONT] method works with the indicies of the characters in the string, which start at [i]zero[/i]. This means that to pring out the last character in the string you'd need to do this:alert(myString.charAt(myString.length[color=red]-1[/color]));
Example:
var myString = "abcd";
alert(myString.length); // Displays "4"
alert(myString.charAt(0)); // Displays "a"
alert(myString.charAt(1)); // Displays "b"
alert(myString.charAt(2)); // Displays "c"
alert(myString.charAt(3)); // Displays "d"

See how that works? I think you should be able to figure it out from here... Good luck!
×

Success!

Help @m0bzk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...