Solved

Finding character position

Posted on 2011-03-15
14
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

696 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