Solved

Finding character position

Posted on 2011-03-15
14
281 Views
Last Modified: 2012-05-11
Hello,

i trying to make the following ,  the java code is asking for the name and a number,
what the number should show the character in that position for example i give the name : persia and the number 3
it should give

PERSIA
R

i did the uppercase part but im stuck at the second part Please help


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />
		
		
		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );
		
		number = parseInt (prompt("give a number"));
		
        </script>
		
		
		
	</body>
	

</html>
</body>
</html>

Open in new window

0
Comment
Question by:kensy11
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136234
you need to use the charAt() method

http://www.w3schools.com/jsref/jsref_charat.asp

alert(name.charAt(2));
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 35136238
alert(name.charAt(number));
0
 

Author Comment

by:kensy11
ID: 35136254
i already did it but not working

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />
		
		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );
		number = parseInt (prompt("give a number"));
		document.write(" character is: " + number + "<br />");
        </script>
	</body>
</html>
</body>
</html>

Open in new window

0
 
LVL 19

Expert Comment

by:Rikin Shah
ID: 35136257
alert(name.charAt(number).toUpperCase());
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136277
This looks like works:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.charAt(number-1));

        </script>



	</body>


</html>
</body>
</html>

Open in new window

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136284
replace line 16 with

document.write(" character is: " + name.charAt(number) + "<br />");
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136289
sorry it should be


document.write(" character is: " + name.charAt(number-1) + "<br />");
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:kensy11
ID: 35136292
aah thanks, i got it now
one other question how can i count the whole text ten
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136301
if you want to count the length of the text, then use name.length

http://www.w3schools.com/jsref/jsref_length_string.asp
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136321
This prints the length of the string

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.charAt(number-1));
	document.write("<br>");

	document.write(name.length);

        </script>



	</body>


</html>
</body>
</html>

Open in new window

0
 

Author Comment

by:kensy11
ID: 35136355
thanks again sorry one other question
 
for example i give the name persia and the number is 2

how can i write the name form the 2 position , in this case i shuld look like  RSIA

thanks again
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136368
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.substring(number-1));
	document.write("<br>");

	document.write(name.length);

        </script>



	</body>


</html>
</body>
</html>

Open in new window

0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 250 total points
ID: 35136379
counting form zero:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.substring(number));
	document.write("<br>");

	document.write(name.length);

        </script>



	</body>


</html>
</body>
</html>

Open in new window

0
 

Author Comment

by:kensy11
ID: 35136383
Thank you all
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now