Solved

Finding character position

Posted on 2011-03-15
14
283 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
reverse digits of a number using for loop 5 36
HTML Relative path 9 29
How to loop bootstrap columns which contain database records 9 22
Bad <form> statement? 9 26
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

920 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

16 Experts available now in Live!

Get 1:1 Help Now